#include <bits/stdc++.h>
using namespace std;
int t;
void solve() {
  int l, r;
  cin >> l >> r;
  int mx;
  int top = r;
  if (top % 2 == 0) top--;
  int bot = top / 2 + 1;
  if (bot >= l)
    mx = top - bot;
  else
    mx = r - l;
  cout << mx << endl;
  return;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
