#T445. OJ积分购物

OJ积分购物

Description

Xiao Wei, as a COIer, frequently submits and solves problems on OJ platforms, earning various types of 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 and makes nn purchases. For each purchase, he carries did_i coins of the ii-th type of points and wants to buy an item worth ss. Determine the number of ways he can pay for each purchase.

Input Format

The first line of input contains five integers: c1c_1, c2c_2, c3c_3, c4c_4, and nn.
The next nn lines each describe a purchase with five integers: d1d_1, d2d_2, d3d_3, d4d_4, and ss.

Output Format

For each purchase, output a single integer representing the number of payment methods.

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.