The N square problem

0

0 votes
Easy
Problem

Mr. N is great in creating problems. He has recently fallen in love with a new problem called Square Problem, in which we have to find as many different squares as possible on an evenly spaced rectangular grid of dots. To find a square, we must identify four dots that form the vertices of a square. Each side of the square must have the same length, of course, but it does not matter what that length is, and the square does not necessarily need to be aligned with the axes of the grid. Mr N earns one point for every different square found in this way. Two squares are different if and only if their sets of four dots are different.
Mr. N has just been given a grid with R rows and C columns of dots. How many different squares can he find in this grid? Since the number might be very large, please output the answer modulo 10^9 + 7 (1000000007).
Input Format:
The first line of the input gives the number of test cases, T. T lines follow. Each line has two integers R and C, the number of dots in each row and column of the grid, respectively.
Output Format:
For each test case, output one line containing ans, where ans is the number of different squares can be found in the grid.
Constraints:

  • 1 ≤ T ≤ 100.
  • 2 ≤ R ≤ 10^9.
  • 2 ≤ C ≤ 10^9

.

Sample Input
4
2 4
3 4
4 4
1000 500
Sample Output
3
10
20
624937395
Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

Each case can be underastood from below diagrams
Case1:
Case 1

Case 2:
Case 2

Case 3:
Case 3

Editor Image

?