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.
#include <bits/stdc++.h>
using namespace std;
const int N = 1234;
long long dp[11][69][N];
int a[100];
void load() {}
long long solve(int Base, long long val) {
  int cnt = 0;
  a[0] = 0;
  while (val > 0) a[++cnt] = val % Base, val /= Base;
  reverse(a + 1, a + 1 + cnt);
  long long ans = 0;
  for (int i = 1; i < cnt; ++i)
    for (int c = 1; c < Base; ++c) ans += dp[Base][i - 1][(1 << c)];
  int Mask = 0;
  for (int i = 0; i < cnt; ++i) {
    if (i) Mask ^= (1 << a[i]);
    for (int c = (i == 0); c < a[i + 1]; ++c)
      ans += dp[Base][cnt - i - 1][Mask ^ (1 << c)];
  }
  if ((Mask ^ (1 << a[cnt])) == 0) ++ans;
  return ans;
}
void trungtt() {
  for (int Base = 2; Base <= 10; ++Base) {
    dp[Base][0][0] = 1;
    for (int i = 1; i <= 64; ++i)
      for (int Mask = 0; Mask < (1 << Base); ++Mask)
        if (dp[Base][i - 1][Mask]) {
          for (int c = 0; c < Base; ++c)
            dp[Base][i][Mask ^ (1 << c)] += dp[Base][i - 1][Mask];
        }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b;
    long long l, r;
    scanf("%d%lld%lld", &b, &l, &r);
    printf("%lld\n", solve(b, r) - solve(b, l - 1));
  }
  return;
}
int main() {
  load();
  trungtt();
  return 0;
}
