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: 
  // package com.company;
  
  
  
  import  java.math.*;
  import java.util.*;
  import java.lang.*;
  import java.io.*;
  
  
  
  public final class Main {
  
      FastReader s;
  
  
      public static void main (String[] args) throws java.lang.Exception
      {
  
          new Main().run();
  
      }
      void run()
      {
          s = new FastReader();
          solve();
      }
      StringBuffer sb;
  
      void solve()
      {
  
          sb = new StringBuffer();
  
  
  
          for(int T = s.nextInt();T > 0;T--)
          {
  
              start();
  
          }
  
           System.out.print(sb);
  
      }
  
  
      void start()
      {
           long l = s.nextLong();
           long r = s.nextLong();
           long max = r%(Math.max(l,r/2+1));
           sb.append(max+"\n");
      }
  
  
      int gcd(int a, int b)
      {
          if (b == 0)
              return a;
          return gcd(b, a % b);
      }
      long gcd(long a, long b)
      {
          if (b == 0)
              return a;
          return gcd(b, a % b);
      }
      long power(long x, long y, long p)
      {
          long res = 1; // Initialize result
  
          // Update x if it is more
          // than or equal to p
          x = x % p;
  
          while (y > 0)
          {
              // If y is odd, multiply
              // x with the result
              if ((y & 1) > 0)
                  res = (res * x) % p;
  
              // y must be even now
              y = y >> 1; // y = y/2
              x = (x * x) % p;
          }
          return res;
      }
  
      int lower_bound(int [] arr , int key)
      {
  
          int i = 0;
          int j = arr.length-1;
          //if(arr[i] > key)return -1;
          if(arr[j] < key)return -1;
  
          while(i<j)
          {
              int mid = (i+j)/2;
  
              if(arr[mid] == key)
              {
                  j = mid;
              }
  
              else if(arr[mid] < key)
              {
                  i = mid+1;
              }
              else
                  j = mid-1;
          }
  
          return i;
      }
  
      int upper_bound(int [] arr , int key)
      {
  
          int i = 0;
          int j = arr.length-1;
          if(arr[j] <= key)return j+1;
  
          while(i<j)
          {
              int mid = (i+j)/2;
  
  
  
              if(arr[mid] <= key)
              {
                  i = mid+1;
              }
              else
                  j = mid;
          }
  
          return i;
      }
  
      
  
      int find(int dsu [],int i)
      {
          if(dsu[i] == i)
              return i;
          dsu[i] = find(dsu,dsu[i]);
          return dsu[i];
      }
  
      void  union(int dsu[] ,int i, int j)
      {
          int a = find(dsu,i);
          int b = find(dsu,j);
          dsu[a] = b;
      }
  
      static void sort(int[] A){
          int n = A.length;
          Random rnd = new Random();
          for(int i=0; i<n; ++i){
              int tmp = A[i];
              int randomPos = i + rnd.nextInt(n-i);
              A[i] = A[randomPos];
              A[randomPos] = tmp;
          }
          Arrays.sort(A);
      }
      static void sort(long[] A){
          int n = A.length;
          Random rnd = new Random();
          for(int i=0; i<n; ++i){
              long tmp = A[i];
              int randomPos = i + rnd.nextInt(n-i);
              A[i] = A[randomPos];
              A[randomPos] = tmp;
          }
          Arrays.sort(A);
      }
      static String sort(String s) {
          Character ch[]=new Character[s.length()];
          for(int i=0;i<s.length();i++) {
              ch[i]=s.charAt(i);
          }
          Arrays.sort(ch);
          StringBuffer st=new StringBuffer("");
          for(int i=0;i<s.length();i++) {
              st.append(ch[i]);
          }
          return st.toString();
      }
  
      //long array input
      public long [] longArr(int len)
      {
          // long arr input
          long [] arr = new long[len];
          String [] strs =  s.nextLine().trim().split("\\s+");
          for(int i =0; i<len; i++)
          {
              arr[i] = Long.parseLong(strs[i]);
  
          }
          return arr;
      }
      // int arr input
      public int [] intArr(int len)
      {
          // long arr input
          int [] arr = new int[len];
          String [] strs =  s.nextLine().trim().split("\\s+");
          for(int i =0; i<len; i++)
          {
              arr[i] = Integer.parseInt(strs[i]);
  
          }
          return arr;
      }
  
      static class FastReader
      {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader()
          {
              br = new BufferedReader(new
                      InputStreamReader(System.in));
          }
  
          String next()
          {
              while (st == null || !st.hasMoreElements())
              {
                  try
                  {
                      st = new StringTokenizer(br.readLine());
                  }
                  catch (IOException  e)
                  {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt()
          {
              return Integer.parseInt(next());
          }
  
          long nextLong()
          {
              return Long.parseLong(next());
          }
  
          double nextDouble()
          {
              return Double.parseDouble(next());
          }
  
          String nextLine()
          {
              String str = "";
              try
              {
                  str = br.readLine();
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
              return str;
          }
      }
  
  
  
  }
  