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:
/**
 * @author vivek
 * programming is thinking, not typing
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {

    private static void solveTC(int __) {

        /* For Google */
//		ans.append("Case #").append(__).append(": ");

        //code start

        int a = scn.nextInt(), b = scn.nextInt(), q = scn.nextInt();
        int[] arr = new int[a * b + 1];
        for (int i = 1; i < arr.length; i++) {
            if ((i % a) % b != (i % b) % a) {
                arr[i] = 1;
            }
            arr[i] += arr[i - 1];
        }

        while (q-- > 0) {
            long l = scn.nextLong();
            long r = scn.nextLong();
            print(getCount(r, arr) - getCount(l - 1, arr) + " ");
        }

        //code end

        print("\n");
    }

    private static long getCount(long n, int[] arr) {

        long ans = (n / (arr.length - 1)) * arr[arr.length - 1];
        ans += arr[(int) (n % (arr.length - 1))];

        return ans;
    }

    /**
     * Don't copy other's templates, make your own <br>
     * It would be much more beneficial
     */

    public static void main(String[] args) {
        scn = new Scanner();
        ans = new StringBuilder();
        int t = scn.nextInt();
//		int t = 1;

//        int limit=               ;
//        sieve(limit);

        /*
        try {
            System.setOut(new PrintStream(new File("file_i_o\\output.txt")));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
*/
        for (int i = 1; i <= t; i++) {
            solveTC(i);
        }
        System.out.print(ans);
    }
    //Stuff for prime start

    /**
     * List containing prime numbers <br>
     * <b>i<sup>th</sup></b> position contains <b>i<sup>th</sup></b> prime number <br>
     * 0th index is <b>null</b>
     */
    private static ArrayList<Integer> listOfPrimes;

    /**
     * query <b>i<sup>th</sup></b> element to get if its prime of not
     */
    private static boolean[] isPrime;

    /**
     * Performs Sieve of Erathosnesis and initialise isPrime array and listOfPrimes list
     *
     * @param limit the number till which sieve is to be performed
     */
    private static void sieve(int limit) {
        listOfPrimes = new ArrayList<>();
        listOfPrimes.add(null);
        boolean[] array = new boolean[limit + 1];

        Arrays.fill(array, true);
        array[0] = false;
        array[1] = false;

        for (int i = 2; i <= limit; i++) {
            if (array[i]) {
                for (int j = i * i; j <= limit; j += i) {
                    array[j] = false;
                }
            }
        }
        isPrime = array;
        for (int i = 0; i <= limit; i++) {
            if (array[i]) {
                listOfPrimes.add(i);
            }
        }
    }
    //stuff for prime end

    /**
     * Calculates the Least Common Multiple of two numbers
     *
     * @param a First number
     * @param b Second Number
     * @return Least Common Multiple of <b>a</b> and <b>b</b>
     */
    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    /**
     * Calculates the Greatest Common Divisor of two numbers
     *
     * @param a First number
     * @param b Second Number
     * @return Greatest Common Divisor of <b>a</b> and <b>b</b>
     */
    private static long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    static void print(Object obj) {
        ans.append(obj.toString());
    }


    static Scanner scn;
    static StringBuilder ans;

    //Fast Scanner
    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
/*
            try {
                br = new BufferedReader(new
                        InputStreamReader(new FileInputStream(new File("file_i_o\\input.txt"))));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
*/
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

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

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        Integer[] nextIntegerArray(int n) {
            Integer[] array = new Integer[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }
            return array;
        }

        String[] nextStringArray() {
            return nextLine().split(" ");
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = next();
            }
            return array;
        }
    }
}