#include<bits/stdc++.h> usingnamespacestd; typedeflonglong ll; constint N = 2e5 + 5; ll t, a, b, q, l, r, sl, sr, sum[N]; intmain(){ cin >> t; while (t--) { cin >> a >> b >> q; int p = a * b; for (int i = 1; i < p; i++) sum[i] = sum[i - 1] + (i % a % b != i % b % a); while (q--) { cin >> l >> r; l--; sl = l / p * sum[p - 1] + sum[l % p]; sr = r / p * sum[p - 1] + sum[r % p]; cout << sr - sl << ' '; } cout << '\n'; } return0; }