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 
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int t = input.nextInt();

        int tCount = 0;

        for(int u=0; u < t; u++) {

            int a = input.nextInt();
            int b = input.nextInt();

            int q = input.nextInt();
            long[] l = new long[q];
            long[] r = new long[q];

            for(int i=0; i < q; i++) {
                l[i] = input.nextLong();
                r[i] = input.nextLong();
            }



            int lcm = lcm(a, b);

            for(int i=0; i < q; i++) {
                long withinCount = countDivisibles(l[i], r[i], lcm);
                withinCount = withinCount * Math.max(a, b);

                long backCounts = 0;

                long actual = r[i] - l[i] + 1;

                long j = l[i] - 1;
                boolean found = false;
                for(; j >= l[i] - 1 - Math.max(a,b); j--) {
                    if (j % lcm == 0) {
                        found = true;
                        break;
                    }
                }

                if (found) {
                    long k = j;
                    for(; k < j + Math.max(a, b); k++) {
                        if (k >= l[i] && k <= r[i]) {
                            backCounts++;
                        }
                    }
                }

                if (withinCount > 0) {
                    long extraCounts = 0;
                    j = r[i];
                    found = false;
                    for (; j >= r[i] - Math.max(a, b); j--) {
                        if (j % lcm == 0) {
                            found = true;
                            break;
                        }
                    }

                    if (found) {
                        long k = j;
                        for (; k < j + Math.max(a, b); k++) {
                            if (k > r[i]) {
                                extraCounts++;
                            }
                        }
                    }

                    withinCount -= Math.max(0, extraCounts);
                }
                long unequals = actual - backCounts - withinCount;

                if (i == 0) {
                    System.out.print(unequals);
                } else {
                    System.out.print(" " + unequals);
                }

            }

            System.out.println("");
        }
    }

    public static long countDivisibles(long a, long b, int m) {
        if (a % m == 0)
            return (b / m) - (a / m) + 1;

        return (b / m) - (a / m);
    }

    public static int gcd(int a, int b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    public static int lcm(int a, int b) {
        return (a*b)/gcd(a, b);
    }
}