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: /* @nikhil_supertramp */
  
  import java.awt.*;
  import java.io.*;
  import java.math.*;
  import java.util.*;
  
  
  public class Main
  {
      public static void main(String[] args)throws Exception
      {
          new Solver().solve();
      }
  }
  
  //  cd competetive-programming/src/Codechef
  //  javac -d ../../classes OneTwo.java
  //  java OneTwo
  //  problem link : https://www.codechef.com/COOK98A/problems/OETW
  
  
  class Solver {
  
      void solve() throws Exception
      {
          
              int t =sc.nextInt();
              while(t-->0){
                  int l = sc.nextInt();
                  int r = sc.nextInt();
                  // find the maximum value of a%b;
                  // get the maximum value of a%b
                  // get the va
                  int mid = r/2;
                  if(mid>=l){
                      sc.println(r-mid-1);
                  }else{
                      sc.println(r-l);
                  }
              }
              
          
          sc.flush();
      }
  
      final Helper sc;
      final int MAXN = 1000_006;
      final long MOD = (long) 1e9 + 7;
  
  
      Solver() {
          sc = new Helper(MOD, MAXN);
          sc.initIO(System.in, System.out);
      }
  
  }
  
  class Helper {
      final long MOD;
      final int MAXN;
      final Random rnd;
  
      public Helper(long mod, int maxn) {
          MOD = mod;
          MAXN = maxn;
          rnd = new Random();
      }
  
      public static int[] sieve;
      public static ArrayList<Integer> primes;
  
      public void setSieve() {
          primes = new ArrayList<>();
          sieve = new int[MAXN];
          int i, j;
          for (i = 2; i < MAXN; ++i)
              if (sieve[i] == 0) {
                  primes.add(i);
                  for (j = i; j < MAXN; j += i) {
                      sieve[j] = i;
                  }
              }
      }
  
  
      public static long[] factorial;
  
      public void setFactorial() {
          factorial = new long[MAXN];
          factorial[0] = 1;
          for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
      }
  
      public long getFactorial(int n) {
          if (factorial == null) setFactorial();
          return factorial[n];
      }
  
      public long ncr(int n, int r) {
          if (r > n) return 0;
          if (factorial == null) setFactorial();
          long numerator = factorial[n];
          long denominator = factorial[r] * factorial[n - r] % MOD;
          return numerator * pow(denominator, MOD - 2, MOD) % MOD;
      }
  
  
      public long[] getLongArray(int size) throws Exception {
          long[] ar = new long[size];
          for (int i = 0; i < size; ++i) ar[i] = nextLong();
          return ar;
      }
  
      public int[] getIntArray(int size) throws Exception {
          int[] ar = new int[size];
          for (int i = 0; i < size; ++i) ar[i] = nextInt();
          return ar;
  	}
  
      public int[] getIntArray(String s)throws Exception
      {
          s = s.trim().replaceAll("\\s+", " ");
          String[] strs = s.split(" ");
          int[] arr = new int[strs.length];
          for(int i = 0; i < strs.length; i++)
          {
              arr[i] =  Integer.parseInt(strs[i]);
          }
          return arr;
      }
  
  	public long gcd(long a, long b) {
          return b == 0 ? a : gcd(b, a % b);
      }
  
      public int gcd(int a, int b) {
          return b == 0 ? a : gcd(b, a % b);
      }
  
  
      public long max(long[] ar) {
          long ret = ar[0];
          for (long itr : ar) ret = Math.max(ret, itr);
          return ret;
      }
  
      public int max(int[] ar) {
          int ret = ar[0];
          for (int itr : ar) ret = Math.max(ret, itr);
          return ret;
      }
  
      public long min(long[] ar) {
          long ret = ar[0];
          for (long itr : ar) ret = Math.min(ret, itr);
          return ret;
      }
  
      public int min(int[] ar) {
          int ret = ar[0];
          for (int itr : ar) ret = Math.min(ret, itr);
          return ret;
      }
  
  
      public long sum(long[] ar) {
          long sum = 0;
          for (long itr : ar) sum += itr;
          return sum;
      }
  
      public long sum(int[] ar) {
          long sum = 0;
          for (int itr : ar) sum += itr;
          return sum;
      }
  
      public void shuffle(int[] ar) {
          int r;
          for (int i = 0; i < ar.length; ++i) {
              r = rnd.nextInt(ar.length);
              if (r != i) {
                  ar[i] ^= ar[r];
                  ar[r] ^= ar[i];
                  ar[i] ^= ar[r];
              }
          }
      }
  
      public void shuffle(long[] ar) {
          int r;
          for (int i = 0; i < ar.length; ++i) {
              r = rnd.nextInt(ar.length);
              if (r != i) {
                  ar[i] ^= ar[r];
                  ar[r] ^= ar[i];
                  ar[i] ^= ar[r];
              }
          }
      }
  
      public long pow(long base, long exp, long MOD) {
          base %= MOD;
          long ret = 1;
          while (exp > 0) {
              if ((exp & 1) == 1) ret = ret * base % MOD;
              base = base * base % MOD;
              exp >>= 1;
          }
          return ret;
      }
  
  
      static byte[] buf = new byte[1000_006];
      static int index, total;
      static InputStream in;
      static BufferedWriter bw;
  
  
      public void initIO(InputStream is, OutputStream os) {
          try {
              in = is;
              bw = new BufferedWriter(new OutputStreamWriter(os));
          } catch (Exception e) {
          }
      }
  
      public void initIO(String inputFile, String outputFile) {
          try {
              in = new FileInputStream(inputFile);
              bw = new BufferedWriter(new OutputStreamWriter(
                      new FileOutputStream(outputFile)));
          } catch (Exception e) {
          }
      }
  
      private int scan() throws Exception {
          if (index >= total) {
              index = 0;
              total = in.read(buf);
              if (total <= 0)
                  return -1;
          }
          return buf[index++];
      }
  
      public String nextLine() throws Exception {
          int c;
          for (c = scan(); c <= 32; c = scan()) ;
          StringBuilder sb = new StringBuilder();
          for (; c >= 32; c = scan())
              sb.append((char) c);
          return sb.toString();
      }
  
      public String next() throws Exception {
          int c;
          for (c = scan(); c <= 32; c = scan()) ;
          StringBuilder sb = new StringBuilder();
          for (; c > 32; c = scan())
              sb.append((char) c);
          return sb.toString();
      }
  
      public int nextInt() throws Exception {
          int c, val = 0;
          for (c = scan(); c <= 32; c = scan()) ;
          boolean neg = c == '-';
          if (c == '-' || c == '+')
              c = scan();
          for (; c >= '0' && c <= '9'; c = scan())
              val = (val << 3) + (val << 1) + (c & 15);
          return neg ? -val : val;
      }
  
      public long nextLong() throws Exception {
          int c;
          long val = 0;
          for (c = scan(); c <= 32; c = scan()) ;
          boolean neg = c == '-';
          if (c == '-' || c == '+')
              c = scan();
          for (; c >= '0' && c <= '9'; c = scan())
              val = (val << 3) + (val << 1) + (c & 15);
          return neg ? -val : val;
      }
  
      public void print(Object a) throws Exception {
          bw.write(a.toString());
      }
  
      public void printsp(Object a) throws Exception {
          print(a);
          print(" ");
      }
  
      public void println() throws Exception {
          bw.write("\n");
      }
  
      public void println(Object a) throws Exception {
          print(a);
          println();
      }
  
      public void flush() throws Exception {
          bw.flush();
      }
  }
  