eolymp
bolt
Try our new interface for solving problems
Problems

Modular Equations

Modular Equations

Time limit 1 second
Memory limit 128 MiB

The laws of modular arithmetic are among the best weapons that we have in our arsenal. We, the wannabe computer scientists, frequently use those laws to keep things manageable. For example if we are to compute the units digit of

2^35^137^14 - 2^45^147^32

we would be able to do that in a flash. However if it requires dealing with equations involving modular arithmetic, many of us may not feel just as comfortable. Fear not; were not going to daunt you with a system of gruesome modular equations we would keep it small and simple. Given the range of three integers a (aminaamax), b (bminbbmax) and m (mminmmmax) you are to find the number of triples (a, b, m) that satisfy the equation:

(a + b) mod m = (a - b) mod m

Here is a sample.

1a2, 2b4, 3 m5

(1 + 2) mod 4 = 3 = (1 - 2) mod 4

(1 + 3) mod 3 = 1 = (1 - 3) mod 3

(1 + 4) mod 4 = 1 = (1 - 4) mod 4

(2 + 2) mod 4 = 0 = (2 - 2) mod 4

(2 + 3) mod 3 = 2 = (2 - 3) mod 3

(2 + 4) mod 4 = 2 = (2 - 4) mod 4

Input data

The first line of the input gives you the number of test cases t (1t20). Each of the next t lines contains the input for each test case which is given by 3 pairs of integer amin, amax, bmin, bmax and mmin, mmax. You can assume that -1000aminamax1000, -1000bminbmax1000, 1mminmmax1000.

Output data

For each test case print in a separate line its number and the number of triples (a, b, m), that satisfy the modular equation.

Examples

Input example #1
3
1 2 2 4 3 5
-100 100 200 350 1 1000
5 9 10 12 2 9
Output example #1
Case 1: 6
Case 2: 318384
Case 3: 45