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.
                    /*
                    TO LEARN
            
                    2-euler tour
                
                    */
                    /*
                    TO SOLVE 
                    codeforces 722 kavi on pairing duty
                    */
                    /*
                    bit manipulation shit
                    1-Computer Systems: A Programmer's Perspective
                    2-hacker's delight
                    3-(02-03-bits-ints)
                    4-machine-basics
                    5-Bits Manipulation tutorialspoint
                    */
                    /*
                    TO WATCH
                    
                    */
                                import java.util.*;
                                import java.math.*;
                                import java.io.*; 
                                import java.util.stream.Collectors;

                                   public class B{
                                static FastScanner scan=new FastScanner();
                                 public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
//return 1 if Alice wins 0 Bob wins
static int dp[][]=new int[1000][2];
static int rec(int x,int turn)
{
    if(dp[x][turn]!=-1)
        return dp[x][turn];
    if(turn==0)
    {
        //Alice
        //find the best for Alice 
        int ret=0;
        for(int i=2;i<x;i++)
        {
            if(x%i==0)
            ret=ret|rec(x-i,turn^1);
        }
        return dp[x][turn]=ret;
    }
    else 
    {
        //Bob
        //find the best for Bob
         int ret=1;
        for(int i=2;i<x;i++)
        {
            if(x%i==0){
          ret=ret&rec(x-i,turn^1);
        }
      
    }
    return dp[x][turn]=ret;
    }
}
static int log2(int x)
{
    int ret=0;
    while(x!=1)
    {
        ret++;
        x/=2;
    }
    return ret;
}
static boolean ispowerofTwo(int x)
{
    while(x%2==0)
        x/=2;
    if(x==1)
        return true;
    return false;
}
static int brute(int l,int r)
{
     int max=0,a=-1,b=-1;
                                    for(int i=l;i<=r;i++)
                                        for(int j=i;j<=r;j++)
                                            {
                                                if(j%i>max)
                                                {
                                                    max=j%i;
                                                    a=i;
                                                    b=j;
                                                }
                                            }
                                        //   out.println(max+" "+a+" "+b);
                                             return max;
}
static int solve(int l,int r)
{
   // for(int )
    int max=0;
    for(int i=r;i>=Math.max(l,r-10);i--)
    {
        //out.println(i);
        int st=Math.max(l,r/2-1),en=Math.min(i,Math.max(l+10,r/2+10));
        for(int j=Math.max(l,r/2-1);j<=en;j++){
          ///  out.println(j+" "+i);
           // if(j%i==244)
             //   out.println(i+" "+j+" "+(j%i));
            max=Math.max(max,i%j);
        }
    }
    return max;
}
                public static void main(String[] args)  throws Exception 
                          {
                     

                         //     scan=new FastScanner("cereal.in");
                         //   out = new PrintWriter("cereal.out");
                             
                                                         /*
                             READING 
                        
                             3-Introduction to DP with Bitmasking codefoces
                             4-Bit Manipulation hackerearth
                             5-read more about mobious and inculsion-exclusion 
                             */
                             /*
                           1- if n is power of two and log2(n) is odd return Bob else return Alice 
                           2- if n is even and not power of two return Alice else return Bob

                             */
                            
                                int tt=1;
                              
                tt=scan.nextInt();
              
                         outer:while(tt-->0)
                                {  
                                    int l=scan.nextInt(),r=scan.nextInt();
                                   
                                          out.println(solve(l,r));
                                  

                                }

                            

    out.close();
                }
        
                        
                               
                                 static long binexp(long a,long n)
                                {
                                    if(n==0)
                                        return 1;
                                    long res=binexp(a,n/2);
                                    if(n%2==1)
                                        return res*res*a;
                                    else 
                                        return res*res;
                                }
                                 
                                static long powMod(long base, long exp, long mod) {
                                       if (base == 0 || base == 1) return base;
                                       if (exp == 0) return 1;
                                       if (exp == 1) return (base % mod+mod)%mod;
                                       long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
                                       R *= R;
                                       R %= mod;
                                       if ((exp & 1) == 1) {
                                           return (base * R % mod+mod)%mod;
                                       }
                                       else return (R %mod+mod)%mod;
                                   }
                                static double dis(double x1,double y1,double x2,double y2)
                                {
                                    return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
                                }
                                static long mod(long x,long y)
                                    {
                                        if(x<0)
                                            x=x+(-x/y+1)*y;
                                        return x%y;
                                    }
                                 public static  long pow(long b, long e) {
                                            long r = 1;
                                            while (e > 0) {
                                                if (e % 2 == 1) r = r * b ;
                                                b = b * b;
                                                e >>= 1;
                                            }
                                            return r;
                                        }
                                private static void sort(long[] arr) {
                                        List<Long> list = new ArrayList<>();
                                        for (long object : arr) list.add(object);
                                        Collections.sort(list);
                                    //Collections.reverse(list);
                                        for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
                                    }
                                private static void sort2(long[] arr) {
                                        List<Long> list = new ArrayList<>();
                                        for (Long object : arr) list.add(object);
                                        Collections.sort(list);
                                    Collections.reverse(list);
                                        for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
                                    }
                                 static class FastScanner
                    {
                        private int BS = 1 << 16;
                        private char NC = (char) 0;
                        private byte[] buf = new byte[BS];
                        private int bId = 0, size = 0;
                        private char c = NC;
                        private double cnt = 1;
                        private BufferedInputStream in;
                     
                        public FastScanner() {
                            in = new BufferedInputStream(System.in, BS);
                        }
                     
                        public FastScanner(String s) {
                            try {
                                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
                            } catch (Exception e) {
                                in = new BufferedInputStream(System.in, BS);
                            }
                        }
                     
                        private char getChar() {
                            while (bId == size) {
                                try {
                                    size = in.read(buf);
                                } catch (Exception e) {
                                    return NC;
                                }
                                if (size == -1) return NC;
                                bId = 0;
                            }
                            return (char) buf[bId++];
                        }
                     
                        public int nextInt() {
                            return (int) nextLong();
                        }
                     
                        public int[] nextInts(int N) {
                            int[] res = new int[N];
                            for (int i = 0; i < N; i++) {
                                res[i] = (int) nextLong();
                            }
                            return res;
                        }
                     
                        public long[] nextLongs(int N) {
                            long[] res = new long[N];
                            for (int i = 0; i < N; i++) {
                                res[i] = nextLong();
                            }
                            return res;
                        }
                     
                        public long nextLong() {
                            cnt = 1;
                            boolean neg = false;
                            if (c == NC) c = getChar();
                            for (; (c < '0' || c > '9'); c = getChar()) {
                                if (c == '-') neg = true;
                            }
                            long res = 0;
                            for (; c >= '0' && c <= '9'; c = getChar()) {
                                res = (res << 3) + (res << 1) + c - '0';
                                cnt *= 10;
                            }
                            return neg ? -res : res;
                        }
                     
                        public double nextDouble() {
                            double cur = nextLong();
                            return c != '.' ? cur : cur + nextLong() / cnt;
                        }
                     
                        public double[] nextDoubles(int N) {
                            double[] res = new double[N];
                            for (int i = 0; i < N; i++) {
                                res[i] = nextDouble();
                            }
                            return res;
                        }
                     
                        public String next() {
                            StringBuilder res = new StringBuilder();
                            while (c <= 32) c = getChar();
                            while (c > 32) {
                                res.append(c);
                                c = getChar();
                            }
                            return res.toString();
                        }
                     
                        public String nextLine() {
                            StringBuilder res = new StringBuilder();
                            while (c <= 32) c = getChar();
                            while (c != '\n') {
                                res.append(c);
                                c = getChar();
                            }
                            return res.toString();
                        }
                     
                        public boolean hasNext() {
                            if (c > 32) return true;
                            while (true) {
                                c = getChar();
                                if (c == NC) return false;
                                else if (c > 32) return true;
                            }
                        }
                    }

                                 static class Pair implements Comparable<Pair>{
                                        public long x, y,z;
                                        public Pair(long x1, long y1,long z1) {
                                            x=x1;
                                            y=y1;
                                            z=z1;
                                        }
                                         public Pair(long x1, long y1) {
                                            x=x1;
                                            y=y1;
                                
                                        }
                                        
                                        @Override
                                        public int hashCode() {
                                            return (int)(x + 31 * y);
                                        }
                                        public String toString() {
                                            return x + " " + y+" "+z;
                                        }
                                        @Override
                                        public boolean equals(Object o){
                                            if (o == this) return true;
                                            if (o.getClass() != getClass()) return false;
                                            Pair t = (Pair)o;
                                            return t.x == x && t.y == y&&t.z==z;
                                        }
                                public int compareTo(Pair o)
                                {
                               if(y==o.y)
                               return (int)(o.x-x);     
                              
                                    return (int)(y-o.y);
                                 
                                    }
                                 
                                }
                                
                                }

                                 
