#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
int pref[500001];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int A, B, Q;
    cin >> A >> B >> Q;
    pref[0] = 0;
    for (int i = 1; i < (A * B); i++) {
      pref[i] = pref[i - 1];
      if ((i % A) % B != (i % B) % A) {
        pref[i]++;
      }
    }
    while (Q--) {
      lli L, R;
      cin >> L >> R;
      int len = A * B;
      lli tillR = (R / len) * pref[len - 1] + pref[R % len];
      L--;
      lli tillL = (L / len) * pref[len - 1] + pref[L % len];
      cout << tillR - tillL << " ";
    }
    cout << "\n";
  }
  return 0;
}
