#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int t, a, b, q, l, r, cnt, c;
  cin >> t;
  while (t--) {
    vector<unsigned long long int> cont;
    cin >> a >> b >> q;
    int arr[40001] = {0};
    c = a * b;
    for (int i = 0; i < c; i++) {
      if ((i % a) % b != (i % b) % a) arr[i] = 1;
    }
    unsigned long long int sum[40002];
    sum[0] = 0;
    for (int i = 1; i < c; i++) {
      sum[i] = sum[i - 1] + arr[i];
    }
    while (q--) {
      cin >> l >> r;
      cnt = (r / c) * sum[a * b - 1];
      cnt += sum[r % c];
      cnt = cnt - ((l / c) * sum[c - 1]);
      if (l % c == 0)
        cnt = cnt - sum[l % c];
      else
        cnt -= sum[l % c - 1];
      cont.push_back(cnt);
    }
    for (auto it : cont) cout << it << " ";
    cout << endl;
  }
}
