Go Back
Consistent brand (100)
Description

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.

Input

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.

Output

For each test case, output a single line with the brand having the longest consistent streak.

Constraints

1 <= T, N, pages of notebook <= 100
1<= |brand name| <=10

Example
Copy Input

Input:
1
9
A C B C B A B C A
2 6 7 4 5 4 5 6 8

Output:
B

Explanation

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).

Good Bye Batch 15-19
#OneLastTime Contest from Batch of 2015-19 of SIES GST



Announcement
Surprise Problem Added!
Contest is extended by 24 hours!

Problem Tags
math, string, adhoc

Supported by our Coding Partner