#include <bits/stdc++.h>
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
std::pair<int, int> operator+(std::pair<int, int> a, std::pair<int, int> b) {
  return {a.first + b.first, a.second + b.second};
}
std::pair<long long, long long> operator+(std::pair<long long, long long> a,
                                          std::pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
std::ostream& operator<<(std::ostream& out, std::pair<int, int> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::ostream& operator<<(std::ostream& out, std::pair<long long, long long> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::istream& operator>>(std::istream& in, std::pair<int, int>& a) {
  in >> a.first >> a.second;
  return in;
}
std::istream& operator>>(std::istream& in, std::pair<long long, long long>& a) {
  in >> a.first >> a.second;
  return in;
}
long long bpow(long long x, long long v) {
  if (v == 0) return 1 % 1000000007;
  if (v % 2 == 1) return (x * bpow(x, v - 1)) % 1000000007;
  long long r = bpow(x, v / 2);
  return (r * r) % 1000000007;
}
using namespace std;
void solve() {
  long long l, r;
  cin >> l >> r;
  long long b = max(l, r / 2 + r % 2);
  cout << max(r % b, max(l, (r - 1)) % b) << "\n";
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}

### Prompt

In Cpp, your task is to solve 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>
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
std::pair<int, int> operator+(std::pair<int, int> a, std::pair<int, int> b) {
  return {a.first + b.first, a.second + b.second};
}
std::pair<long long, long long> operator+(std::pair<long long, long long> a,
                                          std::pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
std::ostream& operator<<(std::ostream& out, std::pair<int, int> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::ostream& operator<<(std::ostream& out, std::pair<long long, long long> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::istream& operator>>(std::istream& in, std::pair<int, int>& a) {
  in >> a.first >> a.second;
  return in;
}
std::istream& operator>>(std::istream& in, std::pair<long long, long long>& a) {
  in >> a.first >> a.second;
  return in;
}
long long bpow(long long x, long long v) {
  if (v == 0) return 1 % 1000000007;
  if (v % 2 == 1) return (x * bpow(x, v - 1)) % 1000000007;
  long long r = bpow(x, v / 2);
  return (r * r) % 1000000007;
}
using namespace std;
void solve() {
  long long l, r;
  cin >> l >> r;
  long long b = max(l, r / 2 + r % 2);
  cout << max(r % b, max(l, (r - 1)) % b) << "\n";
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}

```