#SDNU1508. F.Feed the monkey
F.Feed the monkey
Description
Alice has a monkey, she must feed fruit to the monkey every day.She has three kinds of fruits, bananas, peaches and apples. Every day, she chooses one in three, and pick one of this to feed the monkey. But the monkey is picky, it doesn’t want bananas for more than consecutive days, peaches for more than consecutive days, or apples for more than D3 consecutive days. Now Alice has apples, please help her calculate the number of schemes to feed the monkey.
Input
Multiple test cases. The first line contains an integer , indicating the number of test case. Each test case is a line containing integers $N1, N2, N3, D1, D2, D3 (N1, N2, N3, D1, D2, D3 \leq 50)$.
Output
One line per case. The number of schemes to feed the monkey during (N1+N2+N3) days. The answer is too large so you should mod .
Sample Input
1
2 1 1 1 1 1
Sample Output
6
Hints
Answers are BPBA, BPAB, BABP, BAPB, PBAB, and ABPB(B-banana P-peach A-apple)