#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
ull p[10000000], m;
void build(short a, short b) {
  p[0] = 0;
  m = a * b;
  for (int i = 1; i <= m; i++) {
    p[i] = p[i - 1];
    if ((i % a) % b != (i % b) % a) p[i]++;
  }
}
ull fun(ull s) {
  ull full = s / m;
  ull rem = s % m;
  return p[m] * full + p[rem];
}
ull fun(ull l, ull r) { return fun(r) - fun(l - 1); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    short a, b, q;
    cin >> a >> b >> q;
    build(a, b);
    ull l, r;
    while (q--) {
      cin >> l >> r;
      cout << fun(l, r) << endl;
    }
  }
  return 0;
}
