Problem Author: Kaustubh Badrike
As always, Raju the marketing coordinator is looking for sponsors to the upcoming fest. This time, he’s set his sights on notebook brands. To compare brands, he’s collected N notebooks from all over the campus. However, he doesn’t want just any brand, he’s looking for a brand with the longest consistent streak.
A brand is said to have a consistent streak if the number of pages of the brand’s ith occurrence is the same as the number of pages of the brand’s (i+1)th occurrence. If two brands have the same length of the longest consistent streak, the brand with more number of pages in it’s longest consistent streak is preferred. If the number of pages in the longest consistent streak is also the same for two brands, the brand appearing earlier in the dictionary is preferred.
The first line of input contains an integer T denoting the number of test cases. Each test case consists of three lines.
The first line of each test case consists of a single integer, N.
The second line consists of N space-separated strings, where the nth string denotes the brand of the nth notebook.
The third line consists of N space-separated integers, where the nth integer denotes the number of pages of the nth notebook.
For each test case, output a single line with the brand having the longest consistent streak.
1 <= T, N, pages of notebook <= 100
1<= |brand name| <=10
A C B C B A B C A
2 6 7 4 5 4 5 6 8
The 2nd and 3rd occurrences of B have the same number of pages (5). Hence the brand B has the longest consistent streak (length 2).