TGCD2 - Trending GCD (Hard)

This problem is a harder version of TRENDGCD.

Given nn and mm, compute

S(n,m)=i=1nj=1mijf(gcd(i,j)), S(n, m) = \sum_{i=1}^n \sum_{j=1}^m ij \cdot f(\gcd(i,j)),

where f(n)=(μ(n))2nf(n) = (\mu(n))^2 n and μ(n)\mu(n) is the Möbius function, that is, f(n)=nf(n) = n if nn is square-free and 00 otherwise. Especially, f(1)=1f(1)=1.

Input

The first line contains an integer TT, indicating the number of test cases.

Each of the next TT lines contains two positive integers nn and mm

Output

For each test case, print S(n,m)S(n, m) modulo 109+710^9+7 in a single line.

Example

Input:
5
42 18
35 1
20 25
123456789 987654321
233333333333 233333333333 Output: 306395
630
128819
897063534
355737203

Constraints

There are 6 test files.

Test #0: 1T100001 \leq T \leq 10000, 1n,m1071 \leq n, m \leq 10^7.

Test #1: 1T2001 \leq T \leq 200, 1n,m1081 \leq n, m \leq 10^8.

Test #2: 1T401 \leq T \leq 40, 1n,m1091 \leq n, m \leq 10^9.

Test #3: 1T101 \leq T \leq 10, 1n,m10101 \leq n, m \leq 10^{10}.

Test #4: 1T21 \leq T \leq 2, 1n,m10111 \leq n, m \leq 10^{11}.

Test #5: T=1T = 1, 1n,m2357111317191 \leq n, m \leq 235711131719.

@Speed Addicts: My solution runs in 20.76s (total time). (approx 3.46s per file)

WARNING: The time limit may be somewhat strict.


Added by:liouzhou_101
Date:2019-03-27
Time limit:20s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:TRENDGCD

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.