description: 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.
solution: //import java.io.IOException;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.PrintWriter;
  import java.util.InputMismatchException;
  
  public class TheMiracleandtheSleeper {
      static InputReader inputReader=new InputReader(System.in);
      static void solve()
      {
  
          long l=inputReader.nextLong();
          long r=inputReader.nextLong();
          if (2*l<=r)
          {
              out.println((r-1)/2);
          }
          else
          {
              out.println(r-l);
          }
      }
      static PrintWriter out=new PrintWriter((System.out));
      public static void main(String args[])throws IOException
      {
          int t=inputReader.nextInt();
          while(t-->0)
          {
              solve();
          }
          out.close();
      }
      static class InputReader {
  
          private InputStream stream;
          private byte[] buf = new byte[8192];
          private int curChar, snumChars;
          private SpaceCharFilter filter;
  
          public InputReader(InputStream stream) {
              this.stream = stream;
          }
  
          public int snext() {
              if (snumChars == -1)
                  throw new InputMismatchException();
              if (curChar >= snumChars) {
                  curChar = 0;
                  try {
                      snumChars = stream.read(buf);
                  } catch (IOException e) {
                      throw new InputMismatchException();
                  }
                  if (snumChars <= 0)
                      return -1;
              }
              return buf[curChar++];
          }
  
          public int nextInt() {
              int c = snext();
              while (isSpaceChar(c))
                  c = snext();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = snext();
              }
              int res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = snext();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public long nextLong() {
              int c = snext();
              while (isSpaceChar(c))
                  c = snext();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = snext();
              }
              long res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = snext();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public int[] nextIntArray(int n) {
              int a[] = new int[n];
              for (int i = 0; i < n; i++)
                  a[i] = nextInt();
              return a;
          }
  
          public String readString() {
              int c = snext();
              while (isSpaceChar(c))
                  c = snext();
              StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = snext();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
          public boolean isSpaceChar(int c) {
              if (filter != null)
                  return filter.isSpaceChar(c);
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          public interface SpaceCharFilter {
              public boolean isSpaceChar(int ch);
          }
      }
  }
  