#include <bits/stdc++.h>
using namespace std;
int a, b, q;
vector<long long int> pre;
long long int solve(long long int n) {
  return (n / a * b) * pre[a * b - 1] + pre[n % (a * b)];
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    pre.clear();
    cin >> a >> b >> q;
    long long int sum = 0, ans;
    for (int i = 0; i < a * b; i++) {
      if (i % a % b != i % b % a) sum++;
      pre.push_back(sum);
    }
    while (q--) {
      long long int r, l;
      cin >> l >> r;
      ans = abs(((l - 1) / (a * b)) * pre[a * b - 1] + pre[(l - 1) % (a * b)] -
                ((r / (a * b)) * pre[a * b - 1] + pre[r % (a * b)]));
      cout << ans << "\n";
    }
  }
}
