#include <bits/stdc++.h>
using namespace std;
int check(int n, long long int kard) {
  long long int k = n * (3 * n + 1) / 2;
  if (kard >= k) return 1;
  if (kard < k) return 0;
}
int binary_search(int l, int r, int kard) {
  int n = (l + r) / 2;
  if (check(n, kard)) {
    if (check(n + 1, kard) == 0) {
      return n;
    }
    return binary_search(n, r, kard);
  } else {
    return binary_search(l, n, kard);
  }
}
map<long long int, long long int> m;
int card(long long int kard) {
  if (kard == 0 || kard == 1) return 0;
  if (m.find(kard) != m.end()) return m[kard];
  int n = (-1 + sqrt(1 + 24 * kard)) / 6;
  int t = n * (3 * n + 1) / 2;
  int ex = kard % t;
  return m[kard] = kard / t + card(ex);
}
int main() {
  int n;
  scanf(" %d", &n);
  for (int i = 1; i <= n; ++i) {
    int a;
    scanf(" %d", &a);
    printf("%d\n", card(a));
  }
}
