#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-12;
const double PI = acos(-1.0);
const double angcst = PI / 180.0;
const long long mod = 998244353;
long long max_3(long long a, long long b, long long c) {
  if (a > b && a > c) return a;
  if (b > c) return b;
  return c;
}
long long min_3(long long a, long long b, long long c) {
  if (a < b && a < c) return a;
  if (b < c) return b;
  return c;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long qpow(long long a, long long n) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * a) % mod;
    n >>= 1;
    a = (a * a) % mod;
  }
  return r;
}
long long qmul(long long a, long long b) {
  long long s = (long double)a / mod * b;
  s = a * b - s * mod;
  if (s < 0) s += mod;
  if (s >= mod) s -= mod;
  return s;
}
template <typename _Tp>
inline _Tp read(_Tp& x) {
  char c11 = getchar(), ob = 0;
  x = 0;
  while (c11 ^ '-' && !isdigit(c11)) c11 = getchar();
  if (c11 == '-') c11 = getchar(), ob = 1;
  while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
  if (ob) x = -x;
  return x;
}
const int maxn = 10010;
long long t, a, b;
int main() {
  cin >> t;
  while (t--) {
    cin >> a >> b;
    if (b % 2 == 0 && a == b / 2) {
      cout << a - 1 << endl;
      continue;
    }
    if (b % 2 == 1 && a == b / 2) {
      cout << a << endl;
      continue;
    }
    if (b % 2 == 1) {
      int x = b / 2, y = b / 2 + 1;
      if (x >= a) {
        cout << x << endl;
      } else {
        cout << b - a << endl;
      }
    } else {
      int x = b / 2 - 1, y = b / 2 + 1;
      if (x >= a) {
        cout << x << endl;
      } else {
        cout << b - a << endl;
      }
    }
  }
  return 0;
}

### Prompt

Create a solution in CPP for the following problem:

You are given two integers l and r, l≤ r. Find the largest possible value of a mod b over all pairs (a, b) of integers for which r≥ a ≥ b ≥ l.

As a reminder, a mod b is a remainder we get when dividing a by b. For example, 26 mod 8 = 2.

Input

Each test contains multiple test cases.

The first line contains one positive integer t (1≤ t≤ 10^4), denoting the number of test cases. Description of the test cases follows.

The only line of each test case contains two integers l, r (1≤ l ≤ r ≤ 10^9).

Output

For every test case, output the largest possible value of a mod b over all pairs (a, b) of integers for which r≥ a ≥ b ≥ l.

Example

Input


4
1 1
999999999 1000000000
8 26
1 999999999


Output


0
1
12
499999999

Note

In the first test case, the only allowed pair is (a, b) = (1, 1), for which a mod b = 1 mod 1 = 0.

In the second test case, the optimal choice is pair (a, b) = (1000000000, 999999999), for which a mod b = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-12;
const double PI = acos(-1.0);
const double angcst = PI / 180.0;
const long long mod = 998244353;
long long max_3(long long a, long long b, long long c) {
  if (a > b && a > c) return a;
  if (b > c) return b;
  return c;
}
long long min_3(long long a, long long b, long long c) {
  if (a < b && a < c) return a;
  if (b < c) return b;
  return c;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long qpow(long long a, long long n) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * a) % mod;
    n >>= 1;
    a = (a * a) % mod;
  }
  return r;
}
long long qmul(long long a, long long b) {
  long long s = (long double)a / mod * b;
  s = a * b - s * mod;
  if (s < 0) s += mod;
  if (s >= mod) s -= mod;
  return s;
}
template <typename _Tp>
inline _Tp read(_Tp& x) {
  char c11 = getchar(), ob = 0;
  x = 0;
  while (c11 ^ '-' && !isdigit(c11)) c11 = getchar();
  if (c11 == '-') c11 = getchar(), ob = 1;
  while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
  if (ob) x = -x;
  return x;
}
const int maxn = 10010;
long long t, a, b;
int main() {
  cin >> t;
  while (t--) {
    cin >> a >> b;
    if (b % 2 == 0 && a == b / 2) {
      cout << a - 1 << endl;
      continue;
    }
    if (b % 2 == 1 && a == b / 2) {
      cout << a << endl;
      continue;
    }
    if (b % 2 == 1) {
      int x = b / 2, y = b / 2 + 1;
      if (x >= a) {
        cout << x << endl;
      } else {
        cout << b - a << endl;
      }
    } else {
      int x = b / 2 - 1, y = b / 2 + 1;
      if (x >= a) {
        cout << x << endl;
      } else {
        cout << b - a << endl;
      }
    }
  }
  return 0;
}

```