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.

_Shubham_Jain_06 | 404 |

maggiiiii | 315 |

Savage_19 | 310 |

ritikdagar0203 | 241 |

thanuvinu94 | 233 |

Bishnu Dev Panda | 810 |

_Shubham_Jain_06 | 715 |

okayboss | 652 |

maggiiiii | 598 |

Savage_19 | 576 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.