Gray has received documents this morning and he wants to print as many of them as he can within his budget. He hasn't actually set the printing budget yet, but he wonders how many of the documents he can print at most if he has a certain budget.
Printing each document requires a piece of paper that costs units of money, and some amount of ink. Each of the documents has a size of , and each of the blocks of a document can be empty or can contain an alphanumeric character. If a block is empty, it will be denoted with a dot ('.'). Printing each character requires 1 drop of ink. Each drop of ink costs units of money. So, the cost of printing a document will be the total cost of ink for the document and the cost of 1 piece of paper.
For example, the following is a document with a size of :
1c.
...
.0.``````
To print this document, 5 drops of ink and 1 piece of paper will be required.
As we already know the structure of each of the N documents, Gray now has queries to be answered. In each query, he will give a suggested budget and you will have to answer the query by telling him the maximum number of documents he can print within the budget.
The first line contains an integer () - denoting the number of test cases. For each test case:
The first line contains 3 space-separated integers , , (; ), the number of documents and the dimensions of each documents.
The next line contains 2 space-separated integers , () - denoting the cost of a sheet of paper and cost of a drop of ink, respectively.
Then lines follow, each having characters - which define the documents. Each character can be an alphabet ('A'-'Z', 'a'-'z') or a digit ('0'-'9') or a dot ('.') The first of these lines define the 1st document, the next lines define the 2nd document, and so on.
The next line contains a single integer () - denoting number of queries.
Each of the next lines contain an integer () - budget for each query.
For each test case, print lines of output, one for each query.
For each query, print a single integer - the maximum number of documents Gray can print so that the cost doesn't exceed the budget for that query.
Input | Output |
---|---|
2 3 4 3 1 1 z.A 1c. ... .o. ABC 123 abc 777 ... ... ... ... 5 1 6 20 15 10 1 1 1 1 1 z 1 1 | 1 1 3 2 2 0 |
In the first test case of the sample, printing 1st document will cost 6 units (5 for ink and 1 for piece of paper). Similarly, 2nd document costs 13 units and 3rd one costs 1 units. In 4th query, the budget is 15. With this budget he can either print document 1 and 3 or document 2 and 3. So maximum number of documents printable in this query will be 2. |