#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b, q, i, j, n, x, y, z, ans, z1, ans1, m;
    cin >> a >> b >> q;
    n = a * b;
    m = n;
    n++;
    long long int a1[n];
    for (i = 0; i <= n; i++) {
      a1[i] = 0;
    }
    for (i = 1; i <= n; i++) {
      x = i % a;
      x = x % b;
      y = i % b;
      y = y % a;
      if (x != y) {
        a1[i] = 1;
      } else {
        a1[i] = 0;
      }
    }
    for (i = 1; i <= n; i++) {
      a1[i] = a1[i] + a1[i - 1];
    }
    while (q--) {
      cin >> x >> y;
      x--;
      ans = 0;
      ans1 = 0;
      z = y / m;
      ans = a1[m] * z;
      z = y % m;
      ans = ans + a1[z];
      z = x / m;
      ans1 = a1[m] * z;
      z = x % m;
      ans1 = ans1 + a1[z];
      cout << ans - ans1 << " ";
    }
    cout << endl;
  }
  return 0;
}
