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.*;
import java.util.stream.Collectors;

public class CodeForces {

    public static class ContestSolution extends Solution {

        void solve() {
            int l = in.nextInt();
            int r = in.nextInt();
            int tmp = (r + 1) / 2;
            if (tmp < l) {
                out.println(r - l);
            } else {
                out.println(tmp-1);
            }
        }

    }

    /**
     * add `-Xss256m` to increase stack size
     */
    public static void main(String[] args) {
        boolean local = args.length > 0;
//        boolean local = false;
        String input = local ? "codeforces/input.txt" : null;

        Solution solution = new ContestSolution();
        solution.in = new MyScanner(input);
        solution.out = MyWriter.of(null);
        solution.bm = new Benchmark();
        solution.al = new Algorithm();
        solution.run();
        solution.out.close();
    }

    public static class Solution {
        public MyScanner in;
        public MyWriter out;
        public Benchmark bm;
        public Algorithm al;

        void init() {
        }

        void solve() {
        }

        boolean isMultiTest() {
            return true;
        }

        void run() {
            init();
            if (isMultiTest()) {
                int t = in.nextInt();
                for (int i = 0; i < t; i++) {
                    solve();
                }
            } else {
                solve();
            }
        }

    }

    public static class Algorithm {
        public void sort(int[] arr) {
            List<Integer> tmp = Arrays.stream(arr).boxed().sorted().collect(Collectors.toList());
            for (int i = 0; i < arr.length; i++) {
                arr[i] = tmp.get(i);
            }
        }

        public void sortRev(int[] arr) {
            List<Integer> tmp = Arrays.stream(arr).boxed().sorted(Comparator.comparing((Integer x) -> x).reversed())
                                      .collect(Collectors.toList());
            for (int i = 0; i < arr.length; i++) {
                arr[i] = tmp.get(i);
            }
        }
    }

    public static class ModInt {
        static int MOD = 1000000007;

        public static final ModInt ZERO = new ModInt(0);
        public static final ModInt ONE = new ModInt(1);

        private static final Map<ModInt, ModInt> inverseCache = new HashMap<>();

        private final int value;

        public ModInt(int value) {
            if (value < 0) {
                throw new IllegalArgumentException();
            }
            this.value = value;
        }

        public ModInt add(ModInt other) {
            return new ModInt((int) (((long) this.value + other.value) % MOD));
        }

        public ModInt subtract(ModInt other) {
            return new ModInt((int) (((long) this.value - other.value + MOD) % MOD));
        }

        public ModInt multiply(ModInt other) {
            return new ModInt((int) (((long) this.value * other.value) % MOD));
        }

        public ModInt pow(int degree) {
            if (degree == 0) {
                return ModInt.ONE;
            }
            if (degree % 2 == 1) {
                return this.multiply(pow(degree - 1));
            }
            ModInt tmp = this.pow(degree / 2);
            return tmp.multiply(tmp);
        }

        public ModInt inverse() {
            ModInt tmp = inverseCache.get(this);
            if (tmp == null) {
                tmp = this.pow(MOD - 2);
                inverseCache.put(this, tmp);
            }
            return tmp;
        }

        public ModInt divide(ModInt other) {
            return this.multiply(other.inverse());
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner(String fileName) {
            if (fileName != null) {
                try {
                    br = new BufferedReader(new FileReader(fileName));
                } catch (FileNotFoundException e) {
                    throw new RuntimeException(e);
                }
            } else {
                br = new BufferedReader(new InputStreamReader(System.in));
            }
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextInts(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        boolean[] nextLineBools() {
            String line = nextLine();
            int n = line.length();
            boolean[] booleans = new boolean[n];
            for (int i = 0; i < n; i++) {
                booleans[i] = line.charAt(i) == '1';
            }
            return booleans;
        }

        char[] nextLineChars() {
            String line = nextLine();
            int n = line.length();
            char[] chars = new char[n];
            for (int i = 0; i < n; i++) {
                chars[i] = line.charAt(i);
            }
            return chars;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        public long[] nextLongs(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            try {
                String line = br.readLine();
                if (line == null) {
                    throw new RuntimeException("empty line");
                }
                return line;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static class MyWriter extends PrintWriter {

        public static MyWriter of(String fileName) {
            if (fileName != null) {
                try {
                    return new MyWriter(new FileWriter(fileName));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } else {
                return new MyWriter(new BufferedOutputStream(System.out));
            }
        }

        public MyWriter(FileWriter fileWriter) {
            super(fileWriter);
        }

        public MyWriter(OutputStream out) {
            super(out);
        }

        void println(int[] arr) {
            String line = Arrays.stream(arr).mapToObj(String::valueOf).collect(Collectors.joining(" "));
            println(line);
        }

    }

    public static class Benchmark {
        long time;

        public void start() {
            time = System.currentTimeMillis();
        }

        public long calc() {
            long curTime = System.currentTimeMillis();
            long tmp = curTime - time;
            time = curTime;
            return tmp;
        }

    }
}
