#include <bits/stdc++.h>
using namespace std;
struct Reader {
 public:
  long long int readLong() {
    long long int l;
    cin >> l;
    return l;
  }
  double readDouble() {
    double d;
    cin >> d;
    return d;
  }
  int readInt() {
    int l;
    cin >> l;
    return l;
  }
  int readChar() {
    char d;
    cin >> d;
    return d;
  }
  string readString() {
    string l;
    cin >> l;
    return l;
  }
};
static long long int a[12] = {9,          189,         2889,         38889,
                              488889,     5888889,     68888889,     788888889,
                              8888888889, 98888888889, 1088888888889};
static long long int b[12] = {0,        9,         99,         999,
                              9999,     99999,     999999,     9999999,
                              99999999, 999999999, 9999999999, 99999999999};
void solve(long long int n) {
  if (n < 10) {
    cout << n;
  } else {
    long long int p = 0, q = 0;
    for (long long int i = 1, j = 10; i < 12; i++, j *= 10) {
      if (n <= a[i] && n >= a[i - 1]) {
        p = a[i - 1];
        q = b[i];
        break;
      }
    }
    long long int l = to_string(q).length() + 1,
                  t = q + ((n - p) % l == 0 ? (n - p) / l : (n - p) / l + 1),
                  second = ((n - p) % l == 0 ? (n - p) / l - 1 : (n - p) / l);
    cout << to_string(t)[n - (second * l + p) - 1];
  }
  cout << '\n';
}
pair<pair<long long int, long long int>, pair<long long int, long long int>>
get(long long int l) {
  if (l <= 9045) {
    return make_pair(make_pair(2, 9), make_pair(45, 9));
  }
  if (l <= 1395495) {
    return make_pair(make_pair(3, 99), make_pair(9045, 189));
  }
  if (l <= 189414495) {
    return make_pair(make_pair(4, 999), make_pair(1395495, 2889));
  }
  return make_pair(make_pair(5, 9999), make_pair(189414495, 38889));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Reader in;
  int tt = in.readInt();
  while (tt--) {
    long long int l = in.readLong();
    pair<pair<long long int, long long int>, pair<long long int, long long int>>
        d = get(l);
    if (l <= 45) {
      long long int lp = (sqrt(1 + 8 * l) - 1) / 2;
      if (lp * (lp + 1) / 2 == l) {
        cout << lp << '\n';
      } else {
        cout << l - (lp * (lp + 1) / 2) << '\n';
      }
    } else {
      long long int lp = (sqrt(4 * pow(d.second.second, 2) +
                               4 * d.second.second * d.first.first +
                               pow(d.first.first, 2) +
                               8 * d.first.first * (l - d.second.first)) -
                          2 * d.second.second - d.first.first) /
                         (2 * d.first.first),
                    rp = (((lp * (lp + 1)) / 2) * d.first.first) +
                         (lp * d.second.second) + d.second.first;
      if (l - rp == 0) {
        cout << to_string(
                    lp +
                    d.first.second)[to_string(lp + d.first.second).length() - 1]
             << '\n';
      } else {
        solve(l - rp);
      }
    }
  }
}
