#Q90. 「一本通 3.4 例 2」出纳员问题

「一本通 3.4 例 2」出纳员问题

Description

Original problem from: Asia 2000, problem statement can be found at ZOJ 1420.

A supermarket in Tehran operates 24 hours a day and requires a team of cashiers to meet its needs. The supermarket manager has hired you to solve the problem—the supermarket requires different numbers of cashiers at different times of the day (e.g., only a few at midnight, but many in the afternoon) to provide quality service to customers. He wishes to hire the minimum number of cashiers.

The manager has provided you with the minimum number of cashiers required for each hour of the day—R(0),R(1),,R(23)R(0), R(1), \cdots, R(23). Here, R(0)R(0) represents the minimum number of cashiers needed from midnight to 1:00 AM, R(1)R(1) represents the number needed from 1:00 AM to 2:00 AM, and so on. These requirements are the same every day. There are NN applicants for the job, and each applicant ii works exactly 8 consecutive hours in a 24-hour period, starting at a specific time denoted by tit_i. That is, if the ii-th applicant is hired, they will work continuously for 8 hours starting from time tit_i.

Your task is to write a program that takes R(i)R(i) and tit_i as inputs (all non-negative integers) and calculates the minimum number of cashiers needed to meet the requirements. At any given time, there may be more cashiers working than the corresponding R(i)R(i).

Input Format

The first line contains the number of test cases TT.

For each test case, the first line consists of 24 integers representing R(0),R(1),R(2),,R(23)R(0), R(1), R(2), \cdots, R(23);
The next line contains a positive integer NN, the number of applicants;
The following NN lines each contain an integer tit_i.

There is no blank line between test cases.

Output Format

For each test case, output one line containing an integer representing the minimum number of cashiers needed. If no solution exists, output No Solution.

Sample 1

1
1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
5
0
23
22
1
10

1

Constraints & Notes

For all data, 1T201\le T\le 20, 0N10000\le N\le 1000, 0R(i)10000\le R(i)\le 1000, and 0ti230\le t_i\le 23.