Reminder: in case of any technical issues, you can use the lightweight website
m1.codeforces.com,
m2.codeforces.com,
m3.codeforces.com.
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

E. Salazar Slytherin's Locket

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputHarry 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 *b*_{i}, *l*_{i} and *r*_{i}, 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* ≤ 10^{5}) — number of queries.

Each of the next *q* lines contain three space separated integers *b*_{i}, *l*_{i}, *r*_{i} (2 ≤ *b*_{i} ≤ 10, 1 ≤ *l*_{i} ≤ *r*_{i} ≤ 10^{18}).

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 = 100
_{2}, - 5 = 101
_{2}, - 6 = 110
_{2}, - 7 = 111
_{2}, - 8 = 1000
_{2}, - 9 = 1001
_{2}.

Out of these, only base 2 representation of 9 has even number of 1 and 0. Thus, the answer is 1.

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/17/2019 02:26:03 (e2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|