#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAX = 1e5 + 7;
const long long inf = 1e18L + 5;
const double pi = 3.14159265358979323846;
long long fpow(long long n, long long m) {
  long long res = 1;
  while (m > 0) {
    if (m & 1) {
      res *= n;
    }
    m /= 2;
    n *= n;
  }
  return res;
}
const long long nax = 1e5 + 5;
long long find_rank(long long n) {
  long long res = 1, x;
  long long base = (n * (n + 1)) / 2, d = 1;
  res = 10;
  while (n >= res) {
    x = n - res + 1;
    base += (x * (2 + (x - 1)) / 2);
    res *= 10;
    ++d;
  }
  return base;
}
long long find_rank2(long long n) {
  long long res = 1, x;
  long long base = 0;
  while (n >= res) {
    x = n - res + 1;
    base += x;
    res *= 10;
  }
  return base;
}
void find_val(long long n, long long diff) {
  long long low = 1, high = n, mid;
  while (low <= high) {
    mid = (low + high) / 2;
    if (low == high) {
      break;
    }
    if (find_rank2(mid) < diff) {
      low = mid + 1;
    } else if (find_rank2(mid) > diff) {
      high = mid;
    } else {
      cout << mid % 10 << "\n";
      return;
    }
  }
  long long rnk = find_rank2(mid - 1);
  long long dif = diff - rnk;
  if (mid < 10) {
    cout << mid % 10 << "\n";
  } else if (mid < 100) {
    cout << (mid / fpow(10, 2 - dif)) % 10 << "\n";
  } else if (mid < 1000) {
    cout << (mid / fpow(10, 3 - dif)) % 10 << "\n";
  } else if (mid < 10000) {
    cout << (mid / fpow(10, 4 - dif)) % 10 << "\n";
  } else if (mid < 100000) {
    cout << (mid / fpow(10, 5 - dif)) % 10 << "\n";
  } else if (mid < 1000000) {
    cout << (mid / fpow(10, 6 - dif)) % 10 << "\n";
  } else if (mid < 10000000) {
    cout << (mid / fpow(10, 7 - dif)) % 10 << "\n";
  } else if (mid < 100000000) {
    cout << (mid / fpow(10, 8 - dif)) % 10 << "\n";
  } else if (mid < 1000000000) {
    cout << (mid / fpow(10, 9 - dif)) % 10 << "\n";
  }
}
void solve() {
  long long n;
  cin >> n;
  long long low = 1, high = 1e9, mid;
  while (low <= high) {
    mid = (low + high) / 2;
    if (low == high) {
      break;
    }
    if (find_rank(mid) < n) {
      low = mid + 1;
    } else if (find_rank(mid) > n) {
      high = mid;
    } else {
      cout << mid % 10 << "\n";
      return;
    }
  }
  long long rnk = find_rank(mid - 1);
  long long diff = n - rnk;
  find_val(mid, diff);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
