#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  for (long long int o = 0; o < t; o = o + 1) {
    long long int a, b, q;
    cin >> a >> b >> q;
    long long int c = a * b + 1;
    long long int d[c];
    d[0] = 0;
    for (long long int i = 1; i < c; i = i + 1) {
      d[i] = d[i - 1];
      if (((i % a) % b) != ((i % b) % a)) {
        d[i]++;
      }
    }
    c--;
    long long int l[q], r[q];
    long long int e, f;
    for (long long int i = 0; i < q; i = i + 1) {
      cin >> l[i] >> r[i];
      e = d[r[i] % c] + (r[i] / c) * d[c];
      l[i]--;
      f = d[l[i] % c] + (l[i] / c) * d[c];
      cout << e - f << " ";
    }
    cout << endl;
  }
}
