#include <bits/stdc++.h>
using namespace std;
int f[210 * 210];
int ab;
long long solve(long long n) {
  long long res = f[ab - 1] * (n / ab);
  int m = n % ab;
  res += f[m];
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    ab = a * b;
    memset(f, 0, sizeof f);
    for (int i = (1); i < (ab); ++i) f[i] += (i % a % b) != (i % b % a);
    for (int i = (1); i < (ab); ++i) f[i] += f[i - 1];
    int q;
    cin >> q;
    while (q--) {
      long long q1, q2;
      cin >> q1 >> q2;
      long long res = solve(q2) - solve(q1 - 1);
      cout << res << " ";
    }
    cout << endl;
  }
}
