spoj#GCDMAT. GCD OF MATRIX
GCD OF MATRIX
You have given a matrix of size nxm. Every cell of matrix denote gcd of respective indices. For ex-
A 3x2 matrix have entries
gcd(1,1) | gcd(1,2) |
gcd(2,1) | gcd(2,2) |
gcd(3,1) | gcd(3,2) |
You have given queries i1 j1 i2 j2.
You have to find the sum of matrix formed by upper left corner (i1,j1) and lower right corner (i2,j2).
Input
First line indicates number of testcases. (T<=500)
Next line have space separated two integer n and m. (1<=n,m<=50000).
Next T lines contains queries i1 j1 i2 j2.
where i1<=i2 j1<=j2.
Output
Print ans modulo M for each query in newline. (M=10^9+7)
Example
Input: 2 3 2 1 1 2 2 2 1 3 2</p>Output: 5 5