Problem: You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.

Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.

The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).

Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.

Output

For each test case, print q integers — the answers to the queries of this test case in the order they appear.

Example

Input


2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200


Output


0 0 0 2 4 
0 91 

Solution (in JAVA):

Solution:
import java.util.Scanner;

public class C {

	private static Scanner sc;
	private static StringBuilder sb = new StringBuilder();

	private static void solve(int test) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int q = sc.nextInt();

		int gcd = gcd(a, b);
		int lcm = a * b / gcd;
		boolean[] diff = new boolean[lcm + 1];
		for (int i = 2; i <= lcm; ++i) {
			diff[i] = ((i % a) % b) != ((i % b) % a);
		}
		int[] sum1 = new int[diff.length], sum2 = new int[diff.length];
		for (int i = 2; i <= lcm; ++i) {
			sum1[i] = sum1[i-1];
			if (diff[i]) ++sum1[i];
		}
		for (int i = lcm - 1; i >= 0; --i) {
			sum2[i] = sum2[i + 1];
			if (diff[i]) ++sum2[i];
		}

		for (int i = 0; i < q; ++i) {
			long l = sc.nextLong(), r = sc.nextLong();
			long cnt = 0;

//			for (long j = l; j < Math.min(l + lcm, r + 1); ++j) {
//				if (!diff[(int) (j % lcm)]) continue;
//				cnt += (r - j) / lcm + 1;
//			}

			long x = (l % lcm == 0) ? l : ((l / lcm) + 1) * lcm;
			long y = (r / lcm) * lcm;

			if (x > r) {
				cnt += sum1[(int) (r % lcm)] - sum1[(int) (l % lcm) - 1];
			} else {
				if (x > l) cnt += sum1[lcm] - sum1[(int) (l % lcm) - 1];
				cnt += sum1[lcm] * ((y - x) / lcm);
				if (y < r) cnt += sum1[(int) (r % lcm)];
			}

			sb.append(cnt).append(' ');
		}
		sb.append('\n');
	}

	private static int gcd(int a, int b) {
		int m;
		while (b > 0) {
			m = a % b;
			a = b;
			b = m;
		}
		return a;
	}

	public static void main(String[] args) {

		sc = new Scanner(System.in);
//		solve(0);
		int numTest = sc.nextInt();
		for (int test = 0; test < numTest; ++test) {
			solve(test);
		}
		System.out.println(sb.toString());
		sc.close();
	}

}