#include <bits/stdc++.h>
using namespace std;
long long pref(long long x, vector<long long> &d, long long a, long long b) {
  long long res = ((long long)d.size()) * (x / (a * b));
  res += upper_bound(d.begin(), d.end(), x % (a * b)) - d.begin();
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    int q;
    cin >> a >> b >> q;
    vector<long long> d;
    for (long long i = 0; i < a * b; ++i) {
      if ((i % a) % b != (i % b) % a) d.push_back(i);
    }
    for (int w = 0; w < q; ++w) {
      long long l, r;
      cin >> l >> r;
      cout << pref(r, d, a, b) - pref(l - 1, d, a, b) << ' ';
    }
    cout << '\n';
  }
}
