#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define uint unsigned int
#define ull unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
ll a, b, q;
ll get(ll x) {
ll l = a * b / __gcd(a, b);
ll ans = min(b - 1, x);
ll k = x / l;
if(k > 0){
ans += (k - 1) * (b);
ans += min(b, x - k * l + 1);
}
return ans;
}
void solve(){
cin >> a >> b >> q;
if(a >= b)
swap(a, b);
while(q --) {
ll l, r;
cin >> l >> r;
cout << r - l + 1 - (get(r) - get(l - 1)) << " ";
}
cout << "\n";
}
int main(){
speed();
int t = 1;
cin >> t;
while(t--)solve();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CiAgCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnVzaW5nIG5hbWVzcGFjZSBfX2dudV9wYmRzOwogCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgdWludCB1bnNpZ25lZCBpbnQKI2RlZmluZSB1bGwgIHVuc2lnbmVkIGxvbmcgbG9uZwojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1rIG1ha2Vfc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