#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int n = 1e5 + 5;
const int max_a = 1000;
int level[n], pos[n], first[500];
vector<int> row[500];
ll sttLv(int lv) {
return 1LL * lv * (lv - 1) / 2 + 1;
}
ll endLv(int lv) {
return 1LL * lv * (lv + 1) / 2;
}
int timLv(ll a) {
ll l = 1, r = 2e9, ans = -1;
while (l <= r) {
ll m = (l + r) / 2;
if (endLv(m) >= a) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
return (int)ans;
}
ll sub1(int a) {
vector<vector<int>> tam;
int cur = 1, lv = 1;
while (cur <= max_a) {
vector<int> row;
for (int j = 0; j < lv && cur <= max_a; ++j) {
row.push_back(cur++);
}
tam.push_back(row);
++lv;
}
int r = -1, c = -1;
for (int i = 0; i < tam.size(); ++i) {
for (int j = 0; j < tam[i].size(); ++j) {
if (tam[i][j] == a) {
r = i, c = j;
}
}
}
ll res = 0;
for (int i = 0; i <= r; ++i) {
int left = max(0, c - (r - i));
int right = min((int)tam[i].size() - 1, c);
for (int j = left; j <= right; ++j) {
res += tam[i][j];
}
}
return res;
}
ll sub2(int a) {
int lv = level[a];
int r = pos[a];
ll res = 0;
for (int i = 1; i <= lv; ++i) {
int left = max(1, r - (lv - i));
int right = min(i, r);
for (int j = left - 1; j <= right - 1; ++j) {
res += row[i][j];
}
}
return res;
}
ll sub3(ll a) {
int lv = timLv(a);
ll start = sttLv(lv);
ll r = a - start + 1;
ll res = 0;
for (int i = 1; i <= lv; ++i) {
ll l1 = max(1LL, r - (lv - i));
ll r1 = min(1LL * i, r);
ll len = r1 - l1 + 1;
if (len > 0) {
ll row_start = sttLv(i);
res += (2 * row_start + l1 + r1 - 2) * len / 2;
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int cur = 1, lv = 1;
while (cur <= n) {
first[lv] = cur;
for (int j = 0; j < lv && cur <= n; ++j, ++cur) {
row[lv].push_back(cur);
level[cur] = lv;
pos[cur] = j + 1;
}
++lv;
}
int q;
cin >> q;
while (q--) {
ll a;
cin >> a;
if (a <= max_a) {
cout << sub1((int)a) << '\n';
} else if (a <= n) {
cout << sub2((int)a) << '\n';
} else {
cout << sub3(a) << '\n';
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp1c2luZyBsbCA9IGxvbmcgbG9uZzsKCmNvbnN0IGludCBuID0gMWU1ICsgNTsKY29uc3QgaW50IG1heF9hID0gMTAwMDsKCmludCBsZXZlbFtuXSwgcG9zW25dLCBmaXJzdFs1MDBdOwp2ZWN0b3I8aW50PiByb3dbNTAwXTsKCmxsIHN0dEx2KGludCBsdikgewogICAgcmV0dXJuIDFMTCAqIGx2ICogKGx2IC0gMSkgLyAyICsgMTsKfQoKbGwgZW5kTHYoaW50IGx2KSB7CiAgICByZXR1cm4gMUxMICogbHYgKiAobHYgKyAxKSAvIDI7Cn0KCmludCB0aW1MdihsbCBhKSB7CiAgICBsbCBsID0gMSwgciA9IDJlOSwgYW5zID0gLTE7CiAgICB3aGlsZSAobCA8PSByKSB7CiAgICAgICAgbGwgbSA9IChsICsgcikgLyAyOwogICAgICAgIGlmIChlbmRMdihtKSA+PSBhKSB7CiAgICAgICAgICAgIGFucyA9IG07CiAgICAgICAgICAgIHIgPSBtIC0gMTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBsID0gbSArIDE7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIChpbnQpYW5zOwp9CgpsbCBzdWIxKGludCBhKSB7CiAgICB2ZWN0b3I8dmVjdG9yPGludD4+IHRhbTsKICAgIGludCBjdXIgPSAxLCBsdiA9IDE7CiAgICB3aGlsZSAoY3VyIDw9IG1heF9hKSB7CiAgICAgICAgdmVjdG9yPGludD4gcm93OwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbHYgJiYgY3VyIDw9IG1heF9hOyArK2opIHsKICAgICAgICAgICAgcm93LnB1c2hfYmFjayhjdXIrKyk7CiAgICAgICAgfQogICAgICAgIHRhbS5wdXNoX2JhY2socm93KTsKICAgICAgICArK2x2OwogICAgfQoKICAgIGludCByID0gLTEsIGMgPSAtMTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgdGFtLnNpemUoKTsgKytpKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCB0YW1baV0uc2l6ZSgpOyArK2opIHsKICAgICAgICAgICAgaWYgKHRhbVtpXVtqXSA9PSBhKSB7CiAgICAgICAgICAgICAgICByID0gaSwgYyA9IGo7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgbGwgcmVzID0gMDsKICAgIGZvciAoaW50IGkgPSAwOyBpIDw9IHI7ICsraSkgewogICAgICAgIGludCBsZWZ0ID0gbWF4KDAsIGMgLSAociAtIGkpKTsKICAgICAgICBpbnQgcmlnaHQgPSBtaW4oKGludCl0YW1baV0uc2l6ZSgpIC0gMSwgYyk7CiAgICAgICAgZm9yIChpbnQgaiA9IGxlZnQ7IGogPD0gcmlnaHQ7ICsraikgewogICAgICAgICAgICByZXMgKz0gdGFtW2ldW2pdOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiByZXM7Cn0KCmxsIHN1YjIoaW50IGEpIHsKICAgIGludCBsdiA9IGxldmVsW2FdOwogICAgaW50IHIgPSBwb3NbYV07CgogICAgbGwgcmVzID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IGx2OyArK2kpIHsKICAgICAgICBpbnQgbGVmdCA9IG1heCgxLCByIC0gKGx2IC0gaSkpOwogICAgICAgIGludCByaWdodCA9IG1pbihpLCByKTsKCiAgICAgICAgZm9yIChpbnQgaiA9IGxlZnQgLSAxOyBqIDw9IHJpZ2h0IC0gMTsgKytqKSB7CiAgICAgICAgICAgIHJlcyArPSByb3dbaV1bal07CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJlczsKfQoKbGwgc3ViMyhsbCBhKSB7CiAgICBpbnQgbHYgPSB0aW1MdihhKTsKICAgIGxsIHN0YXJ0ID0gc3R0THYobHYpOwogICAgbGwgciA9IGEgLSBzdGFydCArIDE7CgogICAgbGwgcmVzID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IGx2OyArK2kpIHsKICAgICAgICBsbCBsMSA9IG1heCgxTEwsIHIgLSAobHYgLSBpKSk7CiAgICAgICAgbGwgcjEgPSBtaW4oMUxMICogaSwgcik7CgogICAgICAgIGxsIGxlbiA9IHIxIC0gbDEgKyAxOwogICAgICAgIGlmIChsZW4gPiAwKSB7CiAgICAgICAgICAgIGxsIHJvd19zdGFydCA9IHN0dEx2KGkpOwogICAgICAgICAgICByZXMgKz0gKDIgKiByb3dfc3RhcnQgKyBsMSArIHIxIC0gMikgKiBsZW4gLyAyOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiByZXM7Cn0KCmludCBtYWluKCkgewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShudWxscHRyKTsKCiAgICBpbnQgY3VyID0gMSwgbHYgPSAxOwogICAgd2hpbGUgKGN1ciA8PSBuKSB7CiAgICAgICAgZmlyc3RbbHZdID0gY3VyOwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbHYgJiYgY3VyIDw9IG47ICsraiwgKytjdXIpIHsKICAgICAgICAgICAgcm93W2x2XS5wdXNoX2JhY2soY3VyKTsKICAgICAgICAgICAgbGV2ZWxbY3VyXSA9IGx2OwogICAgICAgICAgICBwb3NbY3VyXSA9IGogKyAxOwogICAgICAgIH0KICAgICAgICArK2x2OwogICAgfQoKICAgIGludCBxOwogICAgY2luID4+IHE7CiAgICB3aGlsZSAocS0tKSB7CiAgICAgICAgbGwgYTsKICAgICAgICBjaW4gPj4gYTsKCiAgICAgICAgaWYgKGEgPD0gbWF4X2EpIHsKICAgICAgICAgICAgY291dCA8PCBzdWIxKChpbnQpYSkgPDwgJ1xuJzsKICAgICAgICB9IGVsc2UgaWYgKGEgPD0gbikgewogICAgICAgICAgICBjb3V0IDw8IHN1YjIoKGludClhKSA8PCAnXG4nOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvdXQgPDwgc3ViMyhhKSA8PCAnXG4nOwogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gMDsKfQo=