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 
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
const int MAXN=2e5+5;
const int M= 998244353;
const int modi6=166666668;

ll cnt(ll num,ll mod,ll d){
	ll ans=num/d;

	ll temp=num%d;

	if(mod==0)
		return ans;

	if(temp>=mod)
		return (ans+1);

	return ans;
}

int main(){	

	int t;
	sfi(t)

	while(t--){
		int a,b,q;
		sfi(a) sfi(b) sfi(q)

		int mat[a+1][b+1];

		memset(mat,-1,sizeof(mat));

		int g=__gcd(a,b);
		int lcm=(a*b)/g;

		for(int l=0;l<lcm;l++){
			int n1=l%a;
			int n2=l%b;

			mat[n1][n2]=l;
		}


		while(q--){
			ll l,r;
			sfl(l) sfl(r)

			set<int> s;

			for(int a1=0;a1<a;a1++){
				for(int b1=0;b1<b;b1++){
					if((a1%b)==(b1%a)){
						if(mat[a1][b1]!=-1){
							s.insert(mat[a1][b1]);
						}
					}
				}
			}

			ll tot=0;

			for(int x:s){
				tot=tot+cnt(r,x,a*b)-cnt(l-1,x,a*b);
			}

			tot=(r-l+1)-tot;

			printf("%lld ", tot);
		}
		printf("\n");
	}

	
	return 0;	
}