Convenience Store Part-Timers

No attempts yetTime limit1sMemory limit128 MB

Problem

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], R[1], \ldots, R[23]. R[0]R[0] is the number needed from 0:00 to 1:00, R[1]R[1] from 1:00 to 2:00, \ldots, and R[23]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.

NN people applied. Each applicant ii works every day for exactly 8 consecutive hours starting at hour T[i]T[i] (0T[i]230 \le T[i] \le 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 RR and TT, find the minimum number of part-timers Jun must hire so that every hour's requirement is met.

Input

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]R[0] through R[23]R[23] separated by spaces (0R[i]10000 \le R[i] \le 1000). The second line contains the number of applicants NN (0N10000 \le N \le 1000). Then follow NN lines, each containing one applicant's start hour T[i]T[i] (0T[i]230 \le T[i] \le 23).

Output

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.