#T648. OJ积分购物

OJ积分购物

Description

Xiao Wei, as a COIer, frequently submits and solves problems on OJ platforms, earning various types of OJ points.

Xiao Wei has four types of OJ points with denominations of c1c_1, c2c_2, c3c_3, and c4c_4.

Xiao Wei goes shopping nn times. For each shopping trip, he carries did_i units of the ii-th type of points and wants to purchase an item worth ss. For each trip, determine how many ways there are to pay for the item.

Input Format

The first line of input consists of five integers: c1c_1, c2c_2, c3c_3, c4c_4, and nn.
The next nn lines each contain five integers describing a shopping trip: d1d_1, d2d_2, d3d_3, d4d_4, and ss.

Output Format

For each shopping trip, output a single integer representing the answer.

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

Hint

【Data Range】

For 100% of the data, it is guaranteed that 1ci,di,s1051≤c_i, d_i, s≤10^5, and 1n10001≤n≤1000.

Source

Adapted from a 2008 provincial selection problem.