Chotu being brother of Mojo Jojo wants to take revenge from Powerpuff Girls for insulting Mojo Jojo.
Chotu hates the Powerpuff girls - hates them to the core. He hates the fact that every single one of those girls have a huge number denoting their power constant. Here are their respective powers: A1d , A2d and A3d .
Chotu wants to find out the exact power units he would need to defeat the powerpuff girls. To find that out, he would need the number of solutions of equation :
A1d + A2d + A3d ≡ M (modulo N)
The above equation should satisfy the following constraint : 0 <= A1, A2, A3 <= Upper Limit.
A1, A2, A3 should also be integers.
Input
First line contains an integer T denoting number of test cases.
Next T lines contain four integers Upper Limit, d, M and N respectively.
Output
For each test case print total number of solutions for above equation. Since answer may be too large print answer modulo 109+7
Constraints
1 <= T <= 10
1 <= Upper Limit <= 1018
0 <= d <= 1018
1 <= N <= 100
0 <= M < N
Note : Consider 00 equal to 1 for this question.
Note : A ≡ B (modulo P) means A modulo P = B modulo P