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 

// 8663601
// VGoma
// Full Credit to Uwi Tenpen from Japan for the input system.
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class C_re {

    InputStream is;
    PrintWriter out;
    String INPUT = ""; // Instead of System.in, so time is accurate.

    void solve() {
        for (int t = ni(); t > 0; t--) {
            go();
        }
    }

    void go() {
        int a = ni(), b = ni(), q = ni();
        long[] mods = new long[a * b];
        mods[0] = 0;
        for (int i = 1; i < mods.length; i++) {
            mods[i] = mods[i - 1];
            if (i % a % b != i % b % a) {
                mods[i]++;
            }
        }
        long num = mods[a * b - 1];
        for (int s = q; s > 0; s--) {
            long l = nl(), r = nl();
            long start = num * (l - 1) / (a * b) + mods[(int)((l - 1) % (a * b))];
            long end = num * r / (a * b) + mods[(int)(r % (a * b))];
            out.print((end - start) + " ");
        }
        out.println();

    }

    void run() throws Exception {
        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

    public static void main(String[] args) throws Exception {
        new C_re().run();
    }

    private byte[] inbuffer = new byte[1024]; // Could be changed for efficiency.
    public int lenbuf = 0, indbuf = 0; // lenbuf is length of buffer, indbuf is current index of buffer.

    private int readByte() {
        if (lenbuf == -1) {
            throw new InputMismatchException();
        }
        if (indbuf >= lenbuf) { // reads next set if necessary.
            indbuf = 0;
            try {
                lenbuf = is.read(inbuffer);
            } catch (IOException e) { // what is the exception for?
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) { // Error (no byte to be read).
                return -1;
            }
        }
        return inbuffer[indbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b));
        return b;
    } // Returns first relevant byte read, moves index in readByte method correspondingly.

    private double nd() {
        return Double.parseDouble(ns());
    } // That simple?

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder(); // Can receive any type of data to concatenate
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buffer = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buffer[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buffer : Arrays.copyOf(buffer, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) {
            map[i] = ns(m);
        }
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = ni();
        }
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (!oj) {
            System.out.println(Arrays.deepToString(o));
        }
    }
}
