#include <bits/stdc++.h>
long long f[25], a[25], sum[25];
long long d[25], l, r, ans, x, w;
long long t[25];
long long xx, check;
int q;
using namespace std;
long long cd(long long x) {
  int dem = -1;
  while (x > 0) {
    x /= 10;
    dem++;
  }
  if (dem == -1) return 0;
  return dem;
}
void prepare() {
  a[1] = 9;
  f[1] = 9;
  sum[1] = 45;
  t[1] = 10;
  t[0] = 1;
  a[0] = 0;
  for (int i = 2; i <= 18; i++) {
    t[i] = t[i - 1] * 10;
    long long x = t[i] - t[i - 1];
    if (i <= 9) {
      f[i] = x * (2 * (a[i - 1] + i) + (x - 1) * i) / 2;
      a[i] = (a[i - 1] + x * i);
      sum[i] += f[i] + sum[i - 1];
      d[i] = i;
    }
  }
}
int main() {
  prepare();
  cin >> q;
  while (q >= 1) {
    q--;
    cin >> x;
    if (x == 1) {
      cout << x << endl;
      continue;
    }
    int lmax;
    for (lmax = 1; lmax <= 9; lmax++)
      if (sum[lmax] > x)
        break;
      else
        continue;
    x -= sum[lmax - 1];
    if (x == 0) {
      cout << 9 << endl;
      continue;
    }
    l = t[lmax - 1];
    r = t[lmax] - 1;
    while (l < r) {
      long long mid = (l + r) / 2;
      if (abs(l - r) == 1) mid++;
      w = cd(mid);
      long long check = a[w] * (mid - t[w] + 1);
      xx = (w + 1) * (mid - t[w] + 1) * (mid - t[w] + 2) / 2;
      if (check + xx < x)
        l = mid;
      else
        r = mid - 1;
    }
    w = cd(l);
    long long check = a[w] * (l - t[w] + 1);
    xx = (w + 1) * (l - t[w] + 1) * (l - t[w] + 2) / 2;
    if (check + xx < x)
      x -= check + xx;
    else
      l = t[lmax];
    if (x == 0) {
      string s = to_string(l);
      cout << s[s.size() - 1] << endl;
      continue;
    }
    r = l + 1;
    l = 0;
    while (l < r) {
      long long mid = (l + r) / 2;
      if (abs(l - r) == 1) mid++;
      w = cd(mid);
      xx = (w + 1) * (mid - t[w] + 1);
      if (a[w] + xx < x)
        l = mid;
      else
        r = mid - 1;
    }
    w = cd(l);
    xx = (w + 1) * (l - t[w] + 1);
    x -= a[w] + xx;
    string s = to_string(l + 1);
    if (x > 0) x--;
    cout << s[x] << endl;
  }
}
