#include <bits/stdc++.h>
using namespace std;
int n;
long long get_simple(long long x) {
  long long h = 10;
  long long sol = 0;
  long long it = 1;
  long long nr = 9;
  while (h <= x) {
    h *= 10;
    sol = sol + it * nr;
    it++;
    nr *= 10;
  }
  h /= 10;
  sol = sol + it * (x - h + 1);
  return sol;
}
long long calc(long long x) {
  long long h = 10;
  long long sol = 0;
  long long it = 1;
  long long nr = 9;
  long long ans = 0;
  while (h <= x) {
    ans = ans + nr * (nr + 1) / 2 * it + sol * nr;
    h *= 10;
    sol = sol + it * nr;
    it++;
    nr *= 10;
  }
  h /= 10;
  long long rest = x - h + 1;
  ans = ans + rest * (rest + 1) / 2 * it + sol * rest;
  return ans;
}
int getdigit(long long x) {
  long long o = 0;
  while (x) {
    x /= 10;
    o++;
  }
  return o;
}
void go(long long x, long long dr) {
  long long st = 0, mij = (st + dr) / 2;
  while (st <= dr) {
    long long sol = get_simple(mij);
    long long o = getdigit(mij);
    if (sol - o < x && x <= sol) {
      for (int i = 0; i < sol - x; i++) mij /= 10;
      cout << mij % 10 << "\n";
      return;
    } else if (sol < x)
      st = mij + 1;
    else
      dr = mij - 1;
    mij = (st + dr) / 2;
  }
}
int main() {
  cin >> n;
  long long x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    long long st = 0, dr = 1000000000, mij = (st + dr) / 2;
    while (st <= dr) {
      long long sol = calc(mij);
      long long nr = get_simple(mij);
      if (sol - nr < x && x <= sol) {
        go(x - sol + nr, mij);
        break;
      } else if (sol < x)
        st = mij + 1;
      else
        dr = mij - 1;
      mij = (st + dr) / 2;
    }
  }
  return 0;
}
