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.io.*;
import java.util.*;

/*
procrastinating
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int INF = (int) (1e9 + 10), MOD = (int) (1e9 + 7), LOGN = 60;
    static final long IINF = (long) (2e18 + 10);

    static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static void solve() {
        int a = in.nextInt();
        int b = in.nextInt();
        int q = in.nextInt();

        int lcm = a * b / gcd(a, b);
        int[] arr = new int[lcm];
        for (int i = 0; i < lcm; i++) {
            if ((i % a) % b != (i % b) % a) {
                arr[i] = 1;
            }
        }
        int[] pre = new int[lcm];
        pre[0] = arr[0];
        for (int i = 1; i < lcm; i++) {
            pre[i] = pre[i - 1] + arr[i];
        }
        int sum = pre[lcm - 1];

        for (int i = 0; i < q; i++) {
            long l = in.nextLong();
            long r = in.nextLong();
            long l1 = l / lcm;
            int l2 = (int) (l % lcm);
            long r1 = r / lcm;
            int r2 = (int) (r % lcm);

            if (l1 == r1) {
                out.print(pre[r2] - (l2 == 0 ? 0 : pre[l2 - 1]));
            } else {
                out.print(sum - (l2 == 0 ? 0 : pre[l2 - 1]) + pre[r2] + (long) sum * (r1 - l1 - 1));
            }
            out.print(' ');
        }
        out.println();

    }

    public static void main(String[] args) throws FileNotFoundException, InterruptedException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("sometext.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));

        Thread thread = new Thread(null, () -> {
            int tests = 1;
            tests = in.nextInt();

            while (tests-- > 0) {
                solve();
            }
        }, "Go", 1 << 28);
        thread.start();
        thread.join();

//        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}