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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class N1342C {
	static ArrayList<Integer> primes;
	static HashSet<Integer> primesH;
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int t=sc.nextInt();
		while(t-->0) {
			int a=sc.nextInt(),b=sc.nextInt(),q=sc.nextInt();
			long g=gcd(a,b);
			if(g==a||g==b) {
				for(int i=0;i<q;i++) {
					sc.nextLong();
					sc.nextLong();
					out.print(0+" ");
				}
				out.println();
			}
			else {
				long lc=a*b/g;
				long ans[]=new long[q];
				for(int i=0;i<q;i++) {
					long x=sc.nextLong(),y=sc.nextLong();
					long upL=y/lc;
					long first=Math.max(a, b);
					long lrg=(y-first*1L*upL-first+1)*1L;
					long maxDiv=lc*1L*upL;
					if(y-maxDiv<first) {
						lrg+=(first-y+maxDiv-1);
					}
					x--;
					long upS=x/lc;
					//int first=Math.max(a, b);
					long sml=(x-first*1L*upS-first+1)*1L;
					long maxDivS=lc*1L*upS;
					if(x-maxDivS<first) {
						sml+=(first-x+maxDivS-1);
					}
					ans[i]=lrg-sml;
					
				}
				for(int i=0;i<q;i++) {
					out.print(ans[i]+" ");
				}
				out.println();
			}
		}
		
		out.close();

	}
	static int gcd (int a, int b) {
	    return b==0?a:gcd (b, a % b);
	}
	static int lcm(int a,int b) {
		return a*b/gcd(a,b);
	}
	static boolean isPrime(long n) {
		if(n<1000000) {
			return primesH.contains((int)n);
		}
		for(int p: primes)
			if(p * p > n)
				break;
			else if(n % p == 0)
				return false;
		return true;
	}
	static void sieveOfEratosthenes(int n)  // O(n*log(log(n)))
    { 
        // Create a boolean array "prime[0..n]" and initialize 
        // all entries it as true. A value in prime[i] will 
        // finally be false if i is Not a prime, else true. 
        boolean prime[] = new boolean[n+1]; 
        for(int i=0;i<n;i++) 
            prime[i] = true; 
          
        for(int p = 2; p*p <=n; p++) 
        { 
            // If prime[p] is not changed, then it is a prime 
            if(prime[p] == true) 
            { 
                // Update all multiples of p 
                for(int i = p*p; i <= n; i += p) 
                    prime[i] = false; 
            } 
        } 
          
        // Print all prime numbers 
        for(int i = 2; i <= n; i++) 
        { 
            if(prime[i] == true) {
               // System.out.print(i + " "); 
                primes.add(i);
                primesH.add(i);
            }
        } 
    } 
	
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public boolean hasNext() {return st.hasMoreTokens();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
			
		public boolean ready() throws IOException {return br.ready(); }


	}

}
