#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  long long a, b, q;
  long long l, r;
  int t;
  long long ans;
  scanf("%d", &t);
  while (t--) {
    cin >> a >> b >> q;
    if (a > b) swap(a, b);
    long long lcm = b / gcd(a, b) * a, tmp, num;
    while (q--) {
      scanf("%I64d%I64d", &l, &r);
      if (a == b || b % a == 0)
        printf("0\n");
      else {
        ans = (r - l + 1) / lcm * (lcm - b);
        num = (r - l + 1) % lcm;
        if (num > 0) {
          tmp = l % lcm;
          if (tmp + num - 1 >= b)
            ans += min(lcm - 1, tmp + num - 1) - max(b, tmp) + 1;
          if (tmp + num - 1 >= lcm) {
            num -= lcm - tmp;
            tmp = 0;
            ans += max(0LL, num - b);
          }
        }
        printf("%I64d%c", ans, q ? ' ' : '\n');
      }
    }
  }
  return 0;
}
