You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.

Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.

The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).

Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.

Output

For each test case, print q integers — the answers to the queries of this test case in the order they appear.

Example

Input


2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200


Output


0 0 0 2 4 
0 91 
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using i64 = long long;
using i32 = int;
using f64 = long double;
template <class Key>
using vec = vector<Key>;
template <class Key>
using heap = priority_queue<Key>;
template <class Key>
using hash_set = unordered_set<Key>;
template <class Key, class Value>
using hash_map = unordered_map<Key, Value>;
using str = string;
using p64 = pair<i64, i64>;
using v64 = vec<i64>;
using vv64 = vec<v64>;
using s64 = set<i64>;
using m64 = map<i64, i64>;
const i64 inf = numeric_limits<i64>::max() / 2;
template <typename T>
inline i64 sz(const T& a) {
  return (i64)(a.size());
}
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <typename T>
inline bool check_min(T& a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <typename T>
inline bool check_max(T& a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
struct Problem {
  Problem(bool multitest = 0) {
    read();
    if (!multitest) solve();
  }
  void solve(), read();
};
signed main() {
  fast();
  Problem(1);
  return 0;
}
i64 a, b, q;
i64 gcd(i64 a, i64 b) {
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
i64 lcm(i64 a, i64 b) { return a * b / gcd(a, b); }
void Problem::solve() {
  i64 from = max(a, b);
  i64 to = lcm(a, b);
  for (i64 i = 0; i < q; i++) {
    i64 l, r;
    cin >> l >> r;
    i64 dl = (l - 1) / to;
    i64 countl = dl * (to - from);
    if ((l - 1) % to >= from) countl += (l - 1) % to - from + 1;
    i64 dr = r / to;
    i64 countr = dr * (to - from);
    if (r % to >= from) countr += r % to - from + 1;
    i64 ans = countr - countl;
    cout << ans << "\n";
  }
}
void Problem::read() {
  i64 tests;
  cin >> tests;
  while (tests--) {
    cin >> a >> b >> q;
    solve();
  }
}
