Given two positive integers x and y, and an array arr[] of positive integers. We need to find the longest prefix index which contains an equal number of x and y. Print the maximum index of largest prefix if exist otherwise print -1.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Each test case contains three integers n, x, and y where n denotes the number of elements in the array a[]. Next line contains space separated n elements in the array a[].

**Output:**

Print an integer which denotes the required prefix (0 based indexing).

**Constraints:**

1<=T<=50

1<=n<=1000

1<=a[i]<=100

1<=x,y<=100

**Example:
Input:**

2

11 7 42

7 42 5 6 42 8 7 5 3 6 7

5 2 3

2 2 3 3 1

9

4

Author: shashwat jain

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

bruceewayne | 119 |

rajupraaa1234 | 110 |

SUZAKU | 104 |

yash_sharan | 104 |

Core_Ka_Bachha | 99 |

mr_kksparrow | 433 |

manvirag982 | 302 |

rajupraaa1234 | 245 |

Exception_404 | 244 |

snow_den_ | 236 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.