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 *b*_{i}, *l*_{i} and *r*_{i}, the base and the range for which you have to find the count of magic numbers.

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}).

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

提交代码