#nt501. 扩展欧几里得3

扩展欧几里得3

Extended Euclidean Algorithm 3

Problem Description

You are given TT test cases. Each case provides a,b,d,l1,r1,l2,r2a, b, d, l_1, r_1, l_2, r_2; output how many integer solutions (x,y)(x, y) of ax+by=da x + b y = d satisfy l1≤x≤r1l_1 \leq x \leq r_1 and l2≤y≤r2l_2 \leq y \leq r_2.

Input Format

The first line contains an integer TT.

The following TT lines each contain seven numbers: a,b,d,l1,r1,l2,r2a, b, d, l_1, r_1, l_2, r_2.

Output Format

Output TT lines, each containing one number: the answer for that case.

Sample Input

3
1 2 5 0 10 0 10
100 150 1000 -10 0 0 10
3 2 1 0 100 0 100

Sample Output

3
2
0

Constraints

For 100%100\% of the data: 1≤T≤1041 \leq T \leq 10^4, 1≤a,b≤1091 \leq a, b \leq 10^9, 1≤d≤10181 \leq d \leq 10^{18}, −1018≤l1≤r1≤1018-10^{18} \leq l_1 \leq r_1 \leq 10^{18}, −1018≤l2≤r2≤1018-10^{18} \leq l_2 \leq r_2 \leq 10^{18}.