#include <bits/stdc++.h>
using namespace std;
using ll = signed long long int;
const int N = 1e5;
ll a, b, ab, q, l, r, res, x[N];
void solve() {
  cin >> a >> b >> q;
  ab = a * b;
  for (int i = 1; i <= ab; i++) {
    x[i] = x[i - 1];
    if (((i % a) % b) != ((i % b) % a)) {
      x[i]++;
    }
  }
  while (q--) {
    cin >> l >> r;
    res = 0LL;
    if (r - l + 1LL >= ab) {
      if (l % ab != 1LL) {
        res += x[ab] - x[(l % ab) - 1];
        l += ab - (l % ab) + 1LL;
      }
      if (r % ab != 1LL) {
        res += x[r % ab];
        r -= r % ab;
      }
      res += max(r - l + 1, 0LL) / ab * x[ab];
    } else {
      if (r % ab >= (l % ab) - 1) {
        res = x[r % ab] - x[(l % ab) - 1];
      } else {
        res = x[r % ab] + x[ab] - x[(l % ab) - 1];
      }
    }
    cout << res << ' ';
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cout << fixed;
  cout.precision(12);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
