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 sys,math,io,os,time,itertools,collections
  mod=10**9+7
  sys.setrecursionlimit(10000)
  i=sys.stdin.readline
  p=sys.stdout.write
  #use sys.stdout.write() (remember to convert to str b4 and concatenate "\n")
  global start,end
  
  #binary search
  def isin(l,x):
      left=0
      right=len(l)-1
      if x<l[0]:
          return -1
      while left<=right:
          mid=left + (right -left)//2
          if l[mid]==x:
              return mid
          elif l[mid]<x:
              ans=mid
              left=mid+1
          else:
              right=mid-1
      return ans
  
  #is palindrome or not
  def ispal(l):
      n=len(l)
      for i in range(n//2+1):
          if l[i]!=l[n-i-1]:
              return False
      return True
  
  #coordinate compression
  def ccarray(l):
      d={l[k]:k for k in range(len(l))}
      m=sorted(d)
      return [d[m[k]] for k in range(len(l))]
  
  #checks if prime or not
  def is_prime(n):
      if n<=3:
          return n>1
      if n%2==0 or n%3==0:
          return False
      k=5
      while k**2<=n:
          if n%k==0 or n%(k+2)==0:
              return False
          k+=6
      return True
  
  #sieve of eratosthenes
  def sieve(n):
      prime=[True for k in range(n+1)]
      p=2
      while p*p<=n:
          if prime[p]==True:
              for k in range(p*p,n+1,p):
                  prime[k]=False
          p+=1
  
  def main():
      l,r=[int(k) for k in i().split()]
      z=r//2 +1
      l=int(max(l,z))
      ans=r%l
      p(str(ans)+"\n")
  
  t=1
  t=int(i())
  start=time.perf_counter()
  for _ in range(t):
      main()
  end=time.perf_counter()
  #print(end-start)