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.*;
  import java.util.*;
  //import java.math.*;  // for bigInteger
  
  public class Main {
  
    static InputReader sc;
    static PrintWriter out;
  
    public static void main(String args[]) throws Exception {
      sc = new InputReader();
      out = new PrintWriter(System.out);
      int t = 1;  
      t = sc.nI();
      for (int tt = 1; tt <= t; ++tt)
        solve(tt);
      out.close();
    }
  
    static void solve(int tn) {
      int l = sc.nI(), r = sc.nI();
      if(r/2+1>=l) out.println(r%(r/2+1));
      else out.println(r%l);
    }
  
    public static class InputReader {
      BufferedReader br;
      StringTokenizer st;
  
      InputReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
      }
  
      public int nI() {
        return Integer.parseInt(n());
      }
  
      public long nL() {
        return Long.parseLong(n());
      }
  
      public double nD() {
        return Double.parseDouble(n());
      }
  
      public String n() {
        while (st == null || !st.hasMoreTokens()) {
          try {
            st = new StringTokenizer(br.readLine());
          } catch (IOException e) {
          }
        }
        return st.nextToken();
      }
    }
  
    /*
     * private final static int m =(int)1e9+7; private static class Pair<T,V> { T
     * first; V second; Pair(final T first, final V second) { this.first = first;
     * this.second = second; } public boolean equals(Object o) { Pair given =
     * (Pair)o; if(given.first == first && given.second == second) return true;
     * return false; } public int hashCode() { long temp =
     * (long)(first.hashCode())*31; temp = (temp+(long)second.hashCode())%m; return
     * (int)temp; } }
     */
  
    public static void debug(final int[]... var) {
      for (final int[] row : var) {
        debug(row);
      }
    }
  
    public static void debug(final long[]... var) {
      for (final long[] row : var) {
        debug(row);
      }
    }
  
    public static void debug(final String[]... var) {
      for (final String[] row : var) {
        debug(row);
      }
    }
  
    public static void debug(final double[]... var) {
      for (final double[] row : var) {
        debug(row);
      }
    }
  
    public static void debug(final char[]... var) {
      for (final char[] row : var) {
        debug(row);
      }
    }
  
    public static void debug(final int... var) {
      for (final int i : var)
        System.err.print(i + " ");
      System.err.println();
    }
  
    public static void debug(final String... var) {
      for (final String i : var)
        System.err.print(i + " ");
      System.err.println();
    }
  
    public static void debug(final double... var) {
      for (final double i : var)
        System.err.print(i + " ");
      System.err.println();
    }
  
    public static void debug(final long... var) {
      for (final long i : var)
        System.err.print(i + " ");
      System.err.println();
    }
  
    public static void debug(final char... var) {
      for (final char c : var)
        System.err.print(c + " ");
      System.err.println();
    }
  
    /*
     * public static <T> void debug(T ...varargs) { // Warning // Heap Pollution
     * might occur // this overrides even 1d and 2d array methods as it is an
     * object... // + i am not using object based array like Integer[] // I am using
     * int[] so that is a problem as i need Wrapper class as an argument for(T
     * val:varargs) System.err.printf("%s ",val); System.err.println(); }
     */
  }
  