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<iostream>
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef long long  ll;
typedef unsigned long long int _ll;
#define INF          1LL<<62
#define mod          1000000007
#define mod1         998244353
#define N            300100
#define PI           3.14159265
#define faster       ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define pb           push_back
#define ppb          pop_back
#define endl         '\n'
#define mii          unordered_map<ll,ll>
#define mis          unordered_map<ll,string>
#define msi          unordered_map<string,ll>
#define rep(i,a,b)   for(ll i=a;i<b;i++)
#define pii          pair<ll,ll>
#define vi           vector<ll>
#define vs           vector<string>
#define all(a)       (a).begin(),(a).end()
#define F             first
#define S            second
 /*ll pow(ll a ,ll b)
 {
  ll ok=a;
  for(ll i=1;i<b;i++)
    ok=ok*a;
  return ok;
 }
 ll  modExpo( ll x,ll n)
{
    if(n==0LL)
        return 1LL;
    else if(n%2LL == 0LL)
    return modExpo((x*x)%mod,n/2LL);
    else
    return (x*modExpo((x*x)%mod,(n-1LL)/2LL))%mod;
}
ll modInverse(ll n)
{
    return modExpo(n,mod-2LL);
} */
int  main()
{
  int  t;
  cin>>t;
  while(t--)
  {
    ll a,b,q;
    cin>>a>>b>>q;
    ll lcm=(a*b)/__gcd(a,b);
    vector<int>vec;
    for(int i=0;i<lcm;i++)
    {
     int x=(i%a)%b;
     int y=(i%b)%a;
     if(x==y)
     {
      vec.pb(i);
     }
    }
    ll t=vec.size();
    while(q--)
    {
      ll l,r;
      cin>>l>>r;
      ll ans=0;
      ll total=r-l+1;
      ll _a=l/lcm;
      ll a=(_a+1)*lcm;
      ll _b=r/lcm;
      ll b=(_b-1)*lcm;
      if(a<=b)
      {
       ans=ans+((((b-a)/lcm)+1)*(t));
      }
       ll x=l%lcm;
       ll y=r%lcm;
       ll _x=lower_bound(all(vec),x)-vec.end();
       ll _z=lower_bound(all(vec),y)-vec.begin();
      if(_a!=_b)
      {
       ans+=(_x+_z);
       if(find(all(vec),y)!=vec.end())
        ans++;
      }
      if(_a==_b)
      {
       for(int i=0;i<t;i++)
       {
        if(vec[i]>=x && vec[i]<=y)
            ans++;
       }
      }
      cout<<total-ans<<endl;
    }
  }
}
