Harry came to know from Dumbledore that Salazar Slytherin's locket is a horcrux. This locket was present earlier at 12 Grimmauld Place, the home of Sirius Black's mother. It was stolen from there and is now present in the Ministry of Magic in the office of Dolorous Umbridge, Harry's former Defense Against the Dark Arts teacher. 

Harry, Ron and Hermione are infiltrating the Ministry. Upon reaching Umbridge's office, they observed a code lock with a puzzle asking them to calculate count of magic numbers between two integers l and r (both inclusive). 

Harry remembered from his detention time with Umbridge that she defined a magic number as a number which when converted to a given base b, all the digits from 0 to b - 1 appear even number of times in its representation without any leading zeros.

You have to answer q queries to unlock the office. Each query has three integers bi, li and ri, the base and the range for which you have to find the count of magic numbers.

Input

First line of input contains q (1 ≤ q ≤ 105) — number of queries.

Each of the next q lines contain three space separated integers bi, li, ri (2 ≤ bi ≤ 10, 1 ≤ li ≤ ri ≤ 1018).

Output

You have to output q lines, each containing a single integer, the answer to the corresponding query.

Examples

Input

2
2 4 9
3 1 10


Output

1
2


Input

2
2 1 100
5 1 100


Output

21
4

Note

In sample test case 1, for first query, when we convert numbers 4 to 9 into base 2, we get: 

  * 4 = 1002, 
  * 5 = 1012, 
  * 6 = 1102, 
  * 7 = 1112, 
  * 8 = 10002, 
  * 9 = 10012. 



Out of these, only base 2 representation of 9 has even number of 1 and 0. Thus, the answer is 1.
import sun.dc.pr.PRError;

import java.io.*;
import java.util.*;

public class Solution {


    static MyScanner sc;
    private static PrintWriter out;
    static long M = 1000000007;


    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();
//
//        stringBuilder.append("5 9\n" +
//                "mahmoud mahmoudbadawy drmahmoud drevil mahmoud\n" +
//                "1 1 5\n" +
//                "1 1 2\n" +
//                "1 2 3\n" +
//                "2 3 mahmoud\n" +
//                "2 4 mahmoud\n" +
//                "2 2 mahmouu\n" +
//                "1 1 5\n" +
//                "1 2 3\n" +
//                "1 1 1\n");


        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }



        out = new PrintWriter(new OutputStreamWriter(System.out));

        initData();
        solveT();
        out.flush();
    }


    static long[][][] tt = new long[11][65][];
    static long[][][] tt2 = new long[11][65][];

    private static void initData() {
        for (int k = 2; k <= 10; k++) {
            tt[k][0] = new long[(1 << k)];
            tt2[k][0] = new long[(1 << k)];
            tt[k][0][0] = 1;


            for (int r = 1; r < 65; r++) {
                tt[k][r] = new long[(1 << k)];
                tt2[k][r] = new long[(1 << k)];
                for (int i = 0; i < k; i++) {
                    for (int t = 0; t < (1 << k); t++) {
                        tt[k][r][t ^ (1 << i)] += tt[k][r - 1][t];
                    }
                }
                for (int i = 1; i < k; i++) {
                    for (int t = 0; t < (1 << k); t++) {
                        tt2[k][r][t ^ (1 << i)] += tt[k][r - 1][t];
                    }
                }
            }
        }
    }


    private static void solve() throws IOException {
        int n = sc.nextInt();
        long l = sc.nextLong();
        long k = sc.nextLong();
        String f = Long.toString(l - 1, n);
        String r = Long.toString(k, n);

//        long m = 0;
//        for (long x = l ; x <= k ; x++) {
//            if(iss(Long.toString(x, n))) {
//                m++;
//            }
//        }
//        out.print( m + " ");


        out.println(count(tt[n], tt2[n], r) - count(tt[n], tt2[n], f));
    }

    private static boolean iss(String s) {
        boolean [] p = new boolean[10];
        for (char x : s.toCharArray()) {
            p[x - '0'] = !p[x - '0'];
        }
        for (boolean r : p) {
            if (r) return false;
        }
        return true;
    }

    private static long count(long[][] longs, long[][] longs1, String f) {
        StringBuilder x = new StringBuilder();
        long res = 0;
        for (int c = 0; c < f.length(); c++) {
            res += longs1[c][0];
        }
        return res + count(longs, f, 0, true);
    }


    private static long count(long[][] longs, String f, int i, boolean fO) {
        if (f.length() == 0) return i == 0 ? 1: 0;
        long res = 0;
        int o = f.length();
        int r = fO ? '1' : '0';
        for (; r < f.charAt(0); r++) {
            res += longs[o - 1][i ^ (1 << (r - '0'))];
        }
        res += count(longs, f.substring(1, f.length()), i ^ (1 << (f.charAt(0) - '0')), false);
        return res;
    }


    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }


    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

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

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

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

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


}