#include <bits/stdc++.h>
using namespace std;
pair<int, int> pii;
pair<long long, long long> pll;
vector<vector<int>> edge;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long a, b, q;
    cin >> a >> b >> q;
    int size = a * b;
    vector<int> pre(size);
    for (int i = 0; i < size; i++) {
      if (i != 0) pre[i] = pre[i - 1];
      if ((i % a) % b != (i % b) % a) pre[i]++;
    }
    while (q--) {
      long long l, r;
      cin >> l >> r;
      long long k1 = (l - 1) / size;
      k1 = 1LL * pre[(l - 1) % size] + k1 * 1LL * pre[size - 1];
      long long k2 = r / size;
      k2 = 1LL * pre[r % size] + k2 * 1LL * pre[size - 1];
      cout << k2 - k1 << " ";
    }
    cout << "\n";
  }
}
