#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  for (long long q = 0; q < t; q++) {
    long long a, b, k;
    cin >> a >> b >> k;
    vector<long long> x(a * b);
    for (long long i = 0; i < a * b; i++) {
      x[i] = (i % a % b != i % b % a);
    }
    long long all = 0;
    for (long long i = 0; i < a * b; i++) {
      all += x[i];
    }
    vector<long long> sum_pref(a * b + 1, 0);
    for (long long i = 0; i < a * b; i++) {
      sum_pref[i + 1] = sum_pref[i] + x[i];
    }
    vector<long long> sum_suf(a * b + 1, 0);
    for (long long i = a * b - 1; i >= 0; i--) {
      sum_suf[i] = sum_suf[i + 1] + x[i];
    }
    for (long long i = 0; i < k; i++) {
      long long l, r;
      cin >> l >> r;
      r++;
      long long ans = (r / (a * b) - l / (a * b) - 1) * all;
      ans += sum_suf[l % (a * b)];
      ans += sum_pref[r % (a * b)];
      cout << ans << " ";
    }
    cout << endl;
  }
  return 0;
}
