#include <bits/stdc++.h>
using namespace std;
int p[40010];
int len;
void build(int a, int b) {
  p[0] = 0;
  len = a * b;
  for (int i = 1; i <= len; i++) {
    p[i] = p[i - 1];
    if ((i % a) % b != (i % b) % a) p[i]++;
  }
}
long long query(long long l) {
  long long cnt = l / len;
  int rem = l % len;
  return p[len] * 1ll * cnt + p[rem];
}
int main() {
  int t, a, b, q;
  cin >> t;
  while (t--) {
    cin >> a >> b >> q;
    build(a, b);
    long long l, r;
    while (q--) {
      cin >> l >> r;
      cout << query(r) - query(l - 1) << " ";
    }
    cout << endl;
  }
}
