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.
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.math.*;
public class Codeforces_741_A
{
	static FastReader sc= new FastReader();
	static PrintWriter out= new PrintWriter(System.out);
	static boolean flag=false;
	public static void main(String args[])
	{
		long start=System.currentTimeMillis();
		int test=sc.nextInt();
		while(test>0)
		{
			flag=false;
			long l=sc.nextLong();
			long r=sc.nextLong();
		long num=r/2;
				if(num>=l)
					System.out.println((r-(num+1)));
				else
				{
					System.out.println(r-l);
				}
			test--;
		}
		
		
		long end=System.currentTimeMillis();
		//System.out.println((end-start)+" "+"m/s");
	}
	static long solve(long a,long b)
	{
		long max=0;
		for(long i=a; i<=b; i++)
		{
			if((b%i)>max)
			{
				max=i;
				flag=true;
			}
		}
		return max;
	}
	
	
	
	
	
	
	static long gcd(long a, long b){    // GCD fun....
    		return b==0?a:gcd(b,a%b);
    }
	static int fact(int num){           // Factorial of int...12
		int point=1;
		   for(int i=1; i<=num; i++)
		   {
			  point=point*i; 
		   }
		   return point;
	}
    static BigInteger fact(BigInteger num){     // Factorial of BigInteger(>10^4)..2second
		BigInteger one=BigInteger.valueOf(1);
		BigInteger m=BigInteger.valueOf(1);
		BigInteger i=one;
		for(i=BigInteger.valueOf(1); num.compareTo(i)>=0; i=i.add(BigInteger.valueOf(1)))
			m=m.multiply(i);
		return m;
	}
    static long fact(long num){                 // lfactorial of Long....(<=16)
	    long point=1;
		   for(long i=1; i<=num; i++)
		   {
			  point=point*i; 
		   }
		   return point;
	}
    static void input(long arr[][],int n,int m){   //long 2d-array input...
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<m; j++)
			{
				arr[i][j]=sc.nextLong();
			}
		}
	}
	static void input(int arr[][],int n,int m){   //int 2d-array input...
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<m; j++)
			{
				arr[i][j]=sc.nextInt();
			}
		}
	}
	static void input(String arr[][],int n,int m){   //String 2d-array input...
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<m; j++)
			{
				arr[i][j]=sc.nextLine();
			}
		}
	}
    static void input(long arr[],int n){            //long 1d array input
		for(int i=0; i<n; i++)
		{
			arr[i]=sc.nextLong();
		}
	}
	 static void input(int arr[],int n){            //int 1d array input
		for(int i=0; i<n; i++)
		{
			arr[i]=sc.nextInt();
		}
	}
	 static void input(char arr[],int n){            //char 1d array input
		for(int i=0; i<n; i++)
		{
			arr[i]=sc.next().charAt(0);
		}
	}
    private static int countDigits(int l) {         //count of digit..Integer
			if (l >= 1000000000) return 10;
			if (l >= 100000000) return 9;
			if (l >= 10000000) return 8;
			if (l >= 1000000) return 7;
			if (l >= 100000) return 6;
			if (l >= 10000) return 5;
			if (l >= 1000) return 4;
			if (l >= 100) return 3;
			if (l >= 10) return 2;
			return 1;
		}
    private static int countDigits(long l) {        // count of Long Digit..
			if (l >= 1000000000000000000L) return 19;
			if (l >= 100000000000000000L) return 18;
			if (l >= 10000000000000000L) return 17;
			if (l >= 1000000000000000L) return 16;
			if (l >= 100000000000000L) return 15;
			if (l >= 10000000000000L) return 14;
			if (l >= 1000000000000L) return 13;
			if (l >= 100000000000L) return 12;
			if (l >= 10000000000L) return 11;
			if (l >= 1000000000L) return 10;
			if (l >= 100000000L) return 9;
			if (l >= 10000000L) return 8;
			if (l >= 1000000L) return 7;
			if (l >= 100000L) return 6;
			if (l >= 10000L) return 5;
			if (l >= 1000L) return 4;
			if (l >= 100L) return 3;
			if (l >= 10L) return 2;
			return 1;
		}
    static class FastReader {                       // Fast input Reader class ...Jaaan
            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 s=""; 
                try { 
                    s=br.readLine(); 
                } 
                catch (IOException e) { 
                    e.printStackTrace(); 
                } 
                return s; 
            } 			
	}			
    static void print(long a[]) {                   //print long array
    		int n=a.length;
    		for(int i=0;i<n;i++) System.out.print(a[i]+" ");
			System.out.println();
    	}
    static void print(int a[]) {                   //print int array
    		int n=a.length;
    		for(int i=0;i<n;i++) System.out.print(a[i]+" ");
			System.out.println();
    	}
    static void print(String a[]) {                   //print String array
    		int n=a.length;
    		for(int i=0;i<n;i++) System.out.print(a[i]+" ");
			System.out.println();
    	}
	static void print(double a[]) {                   //print Double array
    		int n=a.length;
    		for(int i=0;i<n;i++) System.out.print(a[i]+" ");
			System.out.println();
    	}
	static void print(char a[]) {                   //print Char array
    		int n=a.length;
    		for(int i=0;i<n;i++) System.out.print(a[i]+" ");
			System.out.println();
    	}
}
