#include <bits/stdc++.h>
using namespace std;
long long qianzhuihe[11] = {0};
long long stp2weishu[20] = {0};
long long qiuweishu(long long n) {
  long long rs = 0;
  while (1) {
    n /= 10;
    rs++;
    if (n == 0) {
      break;
    }
  }
  return rs;
}
void calcSum() {
  long long a1 = 1;
  long long a2 = a1 * 10;
  long long weishu;
  for (int t1 = 1; t1 <= 10; t1++) {
    weishu = qiuweishu(a1);
    stp2weishu[t1] = stp2weishu[t1 - 1] + weishu * (a2 - a1);
    qianzhuihe[t1] = stp2weishu[t1 - 1] * (a2 - a1) +
                     ((a2 - a1 + 1) * (a2 - a1) / 2) * weishu;
    a1 *= 10;
    a2 = a1 * 10;
  }
}
long long getmin(long long weishu) {
  long long rs = 1;
  for (long long i = 1; i < weishu; i++) rs *= 10;
  return rs;
}
long long getrs(long long n) {
  long long level = 0;
  while (n > stp2weishu[level]) {
    level++;
  }
  n -= stp2weishu[level - 1];
  long long min = getmin(level);
  long long pianyi = (n - 1) / level;
  long long mubiao = min + pianyi;
  long long weishu = (n - 1) % level;
  string s(to_string(mubiao));
  return s[weishu];
}
long long erfenzhi(long long& mid, long long& level, long long& min) {
  return stp2weishu[level - 1] * (mid - min + 1) +
         ((1 + mid - min + 1) * (mid - min + 1) / 2) * level;
}
long long check(long long n) {
  long long level = 0;
  while (n > qianzhuihe[level]) {
    n -= qianzhuihe[level];
    level++;
  }
  long long min = getmin(level);
  long long max = min * 10 - 1;
  long long min2 = min, max2 = max;
  long long mid = 0;
  while (min2 != max2) {
    long long mid = (min2 + max2) / 2;
    if (n <= erfenzhi(mid, level, min)) {
      max2 = mid;
    } else {
      min2 = mid + 1;
    }
  }
  mid = min2;
  if (mid == min) {
    return getrs(n);
  } else {
    long long no = stp2weishu[level - 1] * (mid - min) +
                   ((1 + mid - min) * (mid - min) / 2 * level);
    return getrs(n - no);
  }
}
int main() {
  calcSum();
  long long n, a, b;
  cin >> n;
  for (long long ni = 0; ni < n; ni++) {
    cin >> a;
    cout << check(a) - '0' << endl;
  }
  return 0;
}
