Triangles in the Grid

There is a grid of n ∗ m unit squares, which has n + 1 horizontal lines, m + 1 vertical lines and (n + 1)(m + 1) intersection vertices. You can choose three distinct non-collinear vertices to form a triangle. For example, if n = m = 1, there are 4 vertices, which can form 4 triangles. How many of these triangles have area between A and B (inclusive)? Input The first line contains the number of test cases T (T ≤ 25). Each test case contains four integer n, m, A, B (1 ≤ n, m ≤ 200, 0 ≤ A < B ≤ nm). Output For each test case, print the number of triangles whose area is between A and B, inclusive. Sample Input 4 1101 1212 10 10 20 30 12 34 56 78 Sample Output 4 6 27492 1737488