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.io.*;
import java.util.*;
 
public class _1562a {
    FastScanner scn;
    PrintWriter w;
    PrintStream fs;

    long MOD = 1000000007;
    int N=100000+10;
    long mul(long x, long y) {long res = x * y; return (res >= MOD ? res % MOD : res);}
    long power(long x, long y) {if (y < 0) return 1; long res = 1; x %= MOD; while (y!=0) {if ((y & 1)==1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
    void ruffleSort(int[] a) {int n=a.length;Random r=new Random();for (int i=0; i<a.length; i++) {int oi=r.nextInt(n), temp=a[i];a[i]=a[oi];a[oi]=temp;}Arrays.sort(a);}
    boolean LOCAL;
    void debug(Object... o){if(LOCAL)System.err.println(Arrays.deepToString(o));}
    
    void solve(){

        int t=scn.nextInt();
            while(t-->0)
            {
                   long a=scn.nextLong(),b=scn.nextLong();
                   if(a>b){
                        long v=a;
                        a=b;
                        b=v;
                   }
                   long s=b/2+1;
                   if(s>=a&&s<=b){
                        w.println(b%s);
                   }else{
                       w.println(b%a);
                   }
            
            
            }
        
    }
 
    void run() {
        try {
            long ct = System.currentTimeMillis();
            scn = new FastScanner(new File("input.txt"));
            w = new PrintWriter(new File("output.txt"));
            fs=new PrintStream("error.txt");
            System.setErr(fs);
            LOCAL=true;
 
            solve();
 
            w.close();
            System.err.println(System.currentTimeMillis() - ct);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
 
    void runIO() {
 
        scn = new FastScanner(System.in);
        w = new PrintWriter(System.out);
        LOCAL=false;
 
        solve();
 
        w.close();
    }
 
    class FastScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
 
        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }
 
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }
 
        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        long[] nextLongArray(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
 
    public static void main(String[] args) {
        new _1562a().runIO();
    }
}

