#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int a, b, q;
    cin >> a >> b >> q;
    int rem = a * b;
    vector<int> pref(rem + 1);
    pref[0] = 0;
    for (int x = 1; x <= rem; x++) {
      pref[x] = pref[x - 1];
      if ((x % a) % b != (x % b) % a) pref[x]++;
    }
    vector<long long> res;
    for (int i = 0; i < q; i++) {
      long long L, R;
      cin >> L >> R;
      res.push_back(((R / rem) * 1LL * pref[rem] + pref[R % rem]) -
                    (((L - 1) / rem) * 1LL * pref[rem] + pref[(L - 1) % rem]));
    }
    for (long long i : res) cout << i << ' ';
    cout << '\n';
  }
  return 0;
}
