#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long int a, b, q, l, r, sum = 0, g, k;
    scanf("%lld%lld%lld", &a, &b, &q);
    int arr[a * b];
    arr[0] = 0;
    for (int i = 1; i < a * b; i++) {
      if ((i % a) % b != (i % b) % a)
        arr[i] = arr[i - 1] + 1;
      else
        arr[i] = arr[i - 1];
    }
    while (q--) {
      sum = 0;
      scanf("%lld%lld", &l, &r);
      sum = sum + (r / (a * b)) * arr[a * b - 1];
      sum = sum + arr[r % (a * b)];
      sum = sum - ((l - 1) / (a * b)) * arr[a * b - 1];
      sum = sum - arr[(l - 1) % (a * b)];
      printf("%lld ", sum);
    }
    printf("\n");
  }
  return 0;
}
