#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 123;
const int K = 500;
const int maxn = (int)2e9;
const int mod = 100000007;
const long long inf = 1ll * 1e18 + 123;
int a, b, qq;
int dp[40022];
long long solve2(long long p) {
  long long t = p / (a * b);
  int k = p % (a * b);
  return 1ll * dp[a * b] * t + dp[k];
}
void solve() {
  cin >> a >> b >> qq;
  for (int i = 1; i <= a * b; ++i) {
    dp[i] = dp[i - 1];
    if ((i % a) % b != (i % b) % a) {
      dp[i]++;
    }
  }
  while (qq--) {
    long long l, r;
    cin >> l >> r;
    cout << solve2(r) - solve2(l - 1) << ' ';
  }
  cout << '\n';
}
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    solve();
  }
  return 0;
}
