10
4 108 114
5 30 155
8 193 197
9 71 169
2 163 166
8 120 144
8 22 151
4 21 166
2 46 127
8 38 51
 20
9 142 172
7 132 256
8 245 315
9 496 496
3 345 362
8 13 162
5 342 470
9 16 488
9 467 482
4 471 478
10 92 224
6 228 261
9 54 167
2 402 409
5 9 10
7 225 360
3 438 483
6 252 342
3 491 493
6 296 367
 1
8 1234567890123 123456789012345

0
3
0
1
3
0
5
16
9
1
 0
0
0
0
4
6
13
7
0
0
1
2
3
0
0
2
12
9
1
4
 774752389568

#include <bits/stdc++.h>
using namespace std;
int q;
int b;
long long l, r;
string le, ri;
string sub;
long long dp[15][65][1 << 11];
long long calc(int base, int len, int mask) {
  if (len == 0) {
    return (mask == 0) ? 1 : 0;
  }
  long long &ret = dp[base][len][mask];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 0; i < base; ++i) {
    ret += calc(base, len - 1, mask ^ (1 << i));
  }
  return ret;
}
string to_string(int num) {
  string x;
  x.push_back(num + '0');
  return x;
}
string to_base(long long num, int base) {
  if (num == 0) return "";
  return to_string(num % base) + to_base(num / base, base);
}
long long calc_tot(string &str, int base, int len, int mask,
                   bool leading_zero) {
  if (len == 0) {
    return (mask == 0) ? 1 : 0;
  }
  long long ret = 0;
  for (int i = 0; i <= str[len] - '0'; ++i) {
    if (i == 0 && leading_zero) continue;
    if (i < str[len] - '0') {
      ret += calc(base, len - 1, mask ^ (1 << i));
    } else {
      ret += calc_tot(str, base, len - 1, mask ^ (1 << i), false);
    }
  }
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> q;
  while (q--) {
    cin >> b >> l >> r;
    l--;
    if (l == 0)
      le = "0";
    else
      le = to_base(l, b);
    ri = to_base(r, b);
    long long le_tot = 0, ri_tot = 0;
    sub = "";
    le_tot += calc_tot(le, b, le.size() - 1, 0, true);
    ri_tot += calc_tot(ri, b, ri.size() - 1, 0, true);
    while (sub.size() < le.size()) {
      sub.push_back(b - 1 + '0');
      le_tot += calc_tot(sub, b, sub.size() - 1, 0, true);
    }
    sub = "";
    while (sub.size() < ri.size()) {
      sub.push_back(b - 1 + '0');
      ri_tot += calc_tot(sub, b, sub.size() - 1, 0, true);
    }
    cout << ri_tot << ' ' << le_tot << '\n';
    cout << ri_tot - le_tot << '\n';
  }
  return 0;
}
