While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it seems like it is broken. When he tries to compute 1 + 3 using the calculator, he gets 2 instead of 4. But when he tries computing 1 + 4, he gets the correct answer, 5. Puzzled by this mystery, he opened up his calculator and found the answer to the riddle: the full adders became half adders! 

So, when he tries to compute the sum a + b using the calculator, he instead gets the xorsum a ⊕ b (read the definition by the link: <https://en.wikipedia.org/wiki/Exclusive_or>).

As he saw earlier, the calculator sometimes gives the correct answer. And so, he wonders, given integers l and r, how many pairs of integers (a, b) satisfy the following conditions: $$$a + b = a ⊕ b l ≤ a ≤ r l ≤ b ≤ r$$$

However, Daniel the Barman is going to the bar and will return in two hours. He tells you to solve the problem before he returns, or else you will have to enjoy being blocked.

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.

Then, t lines follow, each containing two space-separated integers l and r (0 ≤ l ≤ r ≤ 10^9).

Output

Print t integers, the i-th integer should be the answer to the i-th testcase.

Example

Input


3
1 4
323 323
1 1000000


Output


8
0
3439863766

Note

a ⊕ b denotes the bitwise XOR of a and b.

For the first testcase, the pairs are: (1, 2), (1, 4), (2, 1), (2, 4), (3, 4), (4, 1), (4, 2), and (4, 3).
    //package com.company;
     
    import java.io.*;
    import java.util.*;
     
    public class Main {
        public static class Task {
     
            public void solve(Scanner sc, PrintWriter pw) throws IOException {
                dp = new long[33];
                Arrays.fill(dp, -1);
                dp2 = new long[33];
                Arrays.fill(dp2, -1);
                int t = sc.nextInt();
                while (t-- > 0) {
                    int l = sc.nextInt();
                    int r = sc.nextInt();
    //                System.err.println(Integer.toBinaryString(l));
    //                System.err.println(Integer.toBinaryString(r));
                    if (l == 0 && r == 0) {
                        pw.println(1);
                    } else {
                        l -= 1;
                        long L = get(l, l);
                        long R = get(r, r);
                        long lr = get(l, r);
    //                    long c = R - 2 * lr + L;
                        pw.println(R - 2 * lr + L);
                    }
    //                System.err.println(t);
                }
    //            System.err.println(T1 + " " + T2);
            }
            long T1, T2;
            public long get(int x, int y) {
                if (x < 0) return 0;
                int[] digitsX = new int[33];
                int[] digitsY = new int[33];
                int mx = 0, my = 0;
                while (x != 0) {
                    digitsX[++mx] = x % 2;
                    x /= 2;
                }
                while (y != 0) {
                    digitsY[++my] = y % 2;
                    y /= 2;
                }
    //            long pow2 = 1;
    //            long val = 0;
    //            long multi = 0;
    //            int move = mx;
    //            while (my > move) {
    ////                if (digitsY[move + 1] == 1) {
    ////                    multi = multi + pow2;
    ////                }
    //                val = val + pow2 * digitsY[move + 1];
    //                pow2 *= 2;
    //                move += 1;
    //            }
    //            multi = val - 1;
                long t0 = System.currentTimeMillis();
                long a1 = solveDP(digitsX, digitsY, my, true, true);
                T1 += System.currentTimeMillis() - t0;
                t0 = System.currentTimeMillis();
    //            long a2 = solveDP2(digitsX, mx, true);
                T2 += System.currentTimeMillis() - t0;
                return a1;
            }
     
            long[] dp;
            long solveDP(int[] digitsX, int[] digitsY, int at, boolean same1, boolean same2) {
                if (!same1 && !same2 && dp[at] != -1) return dp[at];
                if (at == 0) return 1;
                int start1 = 0, start2 = 0;
                int end1 = same1 ? digitsX[at] : 1;
                int end2 = same2 ? digitsY[at] : 1;
                long ret = 0;
                for (int i = start1; i <= end1; i++) {
                    for (int j = start2; j <= end2; j++) {
                        if (i == 1 && j == 1) continue;
                        if (same1 && i == digitsX[at] && same2 && j == digitsY[at]) {
                            ret += solveDP(digitsX, digitsY, at - 1, true, true);
                        } else if (same1 && i == digitsX[at]) {
                            ret += solveDP2(digitsX, at - 1, true);
                        } else if (same2 && j == digitsY[at]) {
                            ret += solveDP2(digitsY, at - 1, true);
                        } else {
                            ret += solveDP(digitsX, digitsY, at - 1, false, false);
                        }
                    }
                }
                if (!same1 && !same2) {
                    dp[at] = ret;
                }
                return ret;
            }
     
            long[] dp2;
            long solveDP2(int[] digits, int at, boolean same1) {
                if (!same1 && dp2[at] != -1) return dp2[at];
                if (at == 0) return 1;
                int start1 = 0;
                int end1 = same1 ? digits[at] : 1;
                long ret = 0;
                for (int i = start1; i <= end1; i++) {
                    ret += (i == 1 ? 1 : 2) * solveDP2(digits, at - 1, same1 && i == digits[at]);
                }
                if (!same1) {
                    dp2[at] = ret;
                }
                return ret;
            }
        }
     
        static long TIME_START, TIME_END;
     
        public static void main(String[] args) throws IOException {
            Scanner sc = new Scanner(System.in);
    //        Scanner sc = new Scanner(new FileInputStream("input"));
            PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
    //        PrintWriter pw = new PrintWriter(new FileOutputStream("input"));
    //
    //        pw.println(100);
    //        Random rnd = new Random();
    //        for (int i = 0; i < 100; i++) {
    //            int l = rnd.nextInt(1000000000);
    //            int r = l + rnd.nextInt(1000000000 - l);
    //            pw.println(l + " " + r);
    //        }
     
            Runtime runtime = Runtime.getRuntime();
            long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
            TIME_START = System.currentTimeMillis();
            Task t = new Task();
            t.solve(sc, pw);
            TIME_END = System.currentTimeMillis();
            long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
            pw.close();
            System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
            System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
        }
     
        static class Scanner {
            StringTokenizer st;
            BufferedReader br;
     
            public Scanner(InputStream s) {
                br = new BufferedReader(new InputStreamReader(s));
            }
     
            public Scanner(FileReader s) throws FileNotFoundException {
                br = new BufferedReader(s);
            }
     
            public String next() throws IOException {
                while (st == null || !st.hasMoreTokens())
                    st = new StringTokenizer(br.readLine());
                return st.nextToken();
            }
     
            public int nextInt() throws IOException {
                return Integer.parseInt(next());
            }
     
            public long nextLong() throws IOException {
                return Long.parseLong(next());
            }
     
            public String nextLine() throws IOException {
                return br.readLine();
            }
     
            public double nextDouble() throws IOException {
                return Double.parseDouble(next());
            }
     
            public boolean ready() throws IOException {
                return br.ready();
            }
        }
    }