A convenience store has just opened on the outskirts of town. Jun, the owner, wants to hire enough part-timers to staff the counter. The number of part-timers needed differs by hour of the day: few at night, many during the day, and so on. Jun wants to satisfy every hourly requirement while hiring as few part-timers as possible.
The number of part-timers required in each hour is given as R[0],R[1],…,R[23]. R[0] is the number needed from 0:00 to 1:00, R[1] from 1:00 to 2:00, …, and R[23] from 23:00 to midnight. The requirements are the same every day, and having more part-timers than required in an hour is fine.
N people applied. Each applicant i works every day for exactly 8 consecutive hours starting at hour T[i] (0≤T[i]≤23). If the 8 hours cross midnight, they wrap into the next day. For example, starting at 20 covers hours 20, 21, 22, 23, 0, 1, 2, 3. Every hired part-timer shows up on time each day and works their full shift.
Given R and T, find the minimum number of part-timers Jun must hire so that every hour's requirement is met.
The first line contains the number of test cases, which is at most 20.
Each test case is given as follows. The first line contains 24 integers R[0] through R[23] separated by spaces (0≤R[i]≤1000). The second line contains the number of applicants N (0≤N≤1000). Then follow N lines, each containing one applicant's start hour T[i] (0≤T[i]≤23).
For each test case, print the minimum number of part-timers on its own line.
If it is impossible to meet all requirements, print No Solution on that line instead.