#include <bits/stdc++.h>
const long long INF = LLONG_MAX;
const long long MOD = 1e9 + 7;
using namespace std;
void fastio() {}
long long gcd(long long r, long long b) {
  long long x = 1;
  while (b != 0) {
    x = b;
    b = r % b;
    r = x;
  }
  return x;
}
void solve() {
  long long a, b, q;
  cin >> a >> b >> q;
  long long c = gcd(a, b);
  c = (a * b) / c;
  if (a > b) swap(a, b);
  while (q--) {
    long long l, r;
    cin >> l >> r;
    long long right = r / c;
    long long left = l / c;
    long long ans = (right - left) * (c - b);
    right = r % c;
    left = l % c;
    if (right >= b) ans += right - b + 1;
    if (left >= b) ans -= left - b;
    cout << ans << ' ';
  }
  cout << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
