#include <bits/stdc++.h>
using namespace std;
long long di[100001], n;
long long sum(long long p) { return p / n * di[n] + di[p % n]; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, q;
    cin >> a >> b >> q;
    n = a * b;
    for (long long i = 1; i <= n; i++) {
      di[i] = di[i - 1];
      if ((i % a) % b != (i % b) % a) di[i]++;
    }
    while (q--) {
      long long l, r;
      cin >> l >> r;
      cout << sum(r) - sum(l - 1) << " ";
    }
    cout << endl;
  }
}
