#c221102. 硬币购物

硬币购物

Coin Shopping

Problem Source

HAOI2008

Problem Description

There are 44 kinds of coins, with face values c1,c2,c3,c4c_1, c_2, c_3, c_4 respectively.

A person goes shopping nn times. For each purchase, he brings did_i coins of the ii-th kind and wants to buy goods worth ss. For each purchase, how many ways are there to pay?

Input Format

The first line contains five integers, representing c1,c2,c3,c4,nc_1, c_2, c_3, c_4, n.

The following nn lines each contain five integers describing one purchase, representing d1,d2,d3,d4,sd_1, d_2, d_3, d_4, s.

For 100%100\% of the data, 1≤ci,di,s≤1051 \leq c_i, d_i, s \leq 10^5 and 1≤n≤10001 \leq n \leq 1000.

Output Format

For each purchase, output one line containing an integer: the answer.

Sample Input

1 2 5 10 2
3 2 3 1 10
1000 2 2 2 900

Sample Output

4
27