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 java.lang.*;
import java.lang.reflect.Array;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    void solve() {
        int q=ni();
        dp=new long[11][60][1<<10][2];
        for(int i=0;i<11;i++) for(int j=0;j<60;j++) for(int k=0;k<(1<<10);k++) Arrays.fill(dp[i][j][k],-1);
        while(q-->0){
            int b=ni(); long l=nl(),r=nl();
            long ans=solve(r,b)- solve(l-1,b);
           pw.println(ans);
        }
    }
    long dp[][][][];
    long solve(long num,int b){
         a=convert(num,b);
        int n=a.length;
        long ans=go(0,0,1,n,b,1);
      // pw.println(ans);
        return ans;


    }
    int a[];
    long go(int i,int  mask,int t,int n,int b,int l){
        if(i>=n){
            if(mask==0 && l!=1) return 1;
            else return 0;
        }
        if(t==0 && l!=1 && dp[b][i][mask][t]!=-1) {
           // pw.print(i+" "+mask+" "+dp[b][i][mask][t]+" ");
           return dp[b][i][mask][t];
        }
        long cc=0;
        int ed=b-1;
        if(t==1) ed=a[i];
        for(int j=0;j<=ed;j++){
            int nmask=mask,nl=l;
            if(!(l==1 && j==0)) {

                nmask ^= (1 << j);
                nl=0;
            }
            cc+=go(i+1,nmask,(t==1 && j==ed)?1:0,n,b,nl);
        }
      //   if(t==0 && dp[b][i][mask][t]!=-1) pw.println(i+" "+mask+" "+dp[b][i][mask][t]+" "+cc);
           //if(i==58 && mask==0 && t==0) pw.println(dp[b][i][mask][t]+" "+cc);
        if(l!=1)
        dp[b][i][mask][t]=cc;
        return cc;
    }


    int [] convert(long n,int b){

        int a[]=new int[60];
        int id=59;
        while(n>0){
            a[id--]=(int)(n%b);
            n/=b;
        }
        return a;
    }

    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }

    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}