TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Hurray.. you've won the grand prize in Felicity 2010!!
Now its time to claim your prize through lucky draw, the procedure of which is given below.


You will take out coupons from the coupon box. Each coupon has a unique prize mentioned on it.


You can get a maximum of N prizes. Once you take a coupon out in a step, you will put it back in the box before continuing next step.


The coupon box contains three types of coupons. Your prize depends on the basis of the coupon you took out.


If the coupon you took out turns out to be of type A, you collect the prize mentioned on it. If this is your Nth prize, you have to stop. Otherwise, you take more coupons and continue the process.


If it turns out to be of type B, you can collect the prize mentioned on the coupon any number of times (but at least one), provided that the total number of prizes dont exceed N. After you have taken, you have to stop, you can't take any more coupons.


If it turns out to be of type C, you collect the prize mentioned on the coupon, but you cant collect anymore coupons and have to stop.


Find the number of ways of getting prizes (modulo 10000).
2 ways are considered different if the ith prize you get are different for some i.

Input Format

First line contains the number of test cases
Each test case consists of 4 integers : Na, Nb, Nc and N.
Na, Nb and Nc corresond to the number of coupons of each type in the box.


Number of test cases <= 10

Na,Nb,Nc < 1000

N<=1010

Output Format

For each test case, print a single line which contains the number of different ways possible modulo 10000

Sample Input 1

1
1 1 2 2

Sample Output 1

8

Hints

Problem Source

Migrated from old NTUJ.

CodeCraft 2010

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200