#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long a, b, q;
    cin >> a >> b >> q;
    vector<long long> prefixsum;
    prefixsum.push_back(0);
    for (long long j = 1; j <= a * b; j++) {
      if ((j % a) % b != (j % b) % a) {
        prefixsum.push_back(prefixsum[j - 1] + 1);
      } else {
        prefixsum.push_back(prefixsum[j - 1]);
      }
    }
    for (long long j = 0; j < q; j++) {
      long long l, r;
      cin >> l >> r;
      if (r <= a * b) {
        cout << prefixsum[r] - prefixsum[l - 1] << " ";
      } else {
        long long right =
            (r / (a * b)) * prefixsum[a * b] + prefixsum[r % (a * b)];
        long long left = ((l - 1) / (a * b)) * prefixsum[a * b] +
                         prefixsum[(l - 1) % (a * b)];
        ;
        cout << right - left << " ";
      }
    }
    cout << "\n";
  }
  return 0;
}
