Loading...
Pocket Money
Time: 1 s
Memory: 500 MB
Rafan is in sixth standard. Every day when he goes to school, Rafan takes some pocket money for his tiffin. On this particular day, he asks his father for money to try different kinds of food. His father gives him a note in the local currency, which pays him the same amount as or more than he originally requested. However, his father, thinking that giving his son extra money might ruin him, decided to reduce the extra amount.
If Rafan's father has notes of 5, 10, 20, 30, and 50, and Rafan wants 18, his father will give him a 20 note, as it is the closest greater value to 18.
Now, you need to determine what kind of note his father should give him .
Input
The first line of input will contain a single integer T(1 ≤ T ≤ 10^5), denoting the number of test cases. Each test case consists of multiple lines of input.
For each test case, the first line contains two integers N (1 ≤ N ≤ 10^5), representing the total days Rafan asks his father for money  d (1 ≤ d ≤ 10^5),
The next line of each test case contains N space-separated integers a1, a2, a3, ..., aN (1 ≤ ai ≤ 10^9), representing the values of the individual notes.
The next line of each test case contains d space-separated integers representing the d1 , s2 , d3 …. denoting the asking amount for each particular day (1 ≤ di ≤ 10^5)
Constraint
Additional constraint on the input: the sum of values of d and n over all test cases does not exceed10^6.
Output
What kind of note should Rafan's father give him on that particular day ? If Rafan's father does not have any note with an amount equal to or even more than his initially requested, then output will be -1.
Examples
Input
Output
2
5 3
5 10 20 30 50
18 10 60
3 1
1 5 10
2
20 10 -1
5
Problem Info
Problem ID 199
Time Limit 1000 ms
Memory Limit 512000 KB
Moderators Falak_Ahmed_Shakib , Alom_Shanto
Statistics
Submit
You need to Login or Registration for submit your solution