#include <bits/stdc++.h>
using namespace std;
const int MAXPR = (int)1e8;
vector<int> primes;
void calcPrimes() {
auto sum = 2LL;
int cnt = 1;
const int S = round(sqrt(MAXPR));
vector<char> sieve(S + 1, true);
vector<array<int, 2>> cp;
for (int i = 3; i < S; i += 2) {
if (!sieve[i])
continue;
cp.push_back({i, (i * i - 1) / 2});
for (int j = i * i; j <= S; j += 2 * i)
sieve[j] = false;
}
primes.push_back(0);
primes.push_back(2);
//vector<char> block(S);
std::bitset<10001> block;
int high = (MAXPR - 1) / 2;
for (int low = 0; low <= high; low += S) {
//fill(block.begin(), block.end(), true);
block.set();
for (auto &i : cp) {
int p = i[0], idx = i[1];
for (; idx < S; idx += p)
block[idx] = false;
i[1] = idx - S;
}
if (low == 0)
block[0] = false;
for (int i = 0; i < S && low + i <= high; i++)
if (block[i]){
++cnt, sum += (low + i) * 2 + 1;
primes.push_back((low + i) * 2 + 1);
}
};
}
vector<uint> trig;
void init(){
for(uint i=1;i<=3450;i++){
trig.push_back(i*(i+1)/2);
}
}
inline int scan()
{
int z=0;
char c;
do{ c=getchar_unlocked(); } while(c<'0');
for(;c>='0';c=getchar_unlocked()) z = (z<<3) + (z<<1) + (c&15);
return z;
}
inline void fastWrite(unsigned a,unsigned b)
{
char snum[32];
int i=0;
do
{
snum[i++]=a%10+'0';
a=a/10;
} while(a);
snum[i++]=' ';
do
{
snum[i++]=b%10+'0';
b=b/10;
}
while(b);
i=i-1;
while (i>=0)
putchar_unlocked(snum[i--]);
putchar_unlocked('\n');
}
int main()
{
unsigned tc;
unsigned n;
calcPrimes();
//init();
int x=0,y=0,v=0,lb=0,z=0,ans =0,c;
tc = scan();
while(tc--)
{
n = scan();
c = lower_bound(primes.begin(),primes.end(), n)-primes.begin();
if (n==primes[c]){
lb = c;
y = 0;
x = sqrt(lb);
while(y < lb)
{
y = x*(x+1);
y>>=1;
x+=1;
v = x;
}
v = v - 1;
z = v-1;
ans = lb-((z*(z+1))>>1);
fastWrite(ans,v);
}else{
print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GlkeCA8IFM7IGlkeCArPSBwKQogICAgICAgICAgICAgICAgYmxvY2tbaWR4XSA9IGZhbHNlOwogICAgICAgICAgICBpWzFdID0gaWR4IC0gUzsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaWYgKGxvdyA9PSAwKQogICAgICAgICAgICBibG9ja1swXSA9IGZhbHNlOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgUyAmJiBsb3cgKyBpIDw9IGhpZ2g7IGkrKykKICAgICAgICAgICAgaWYgKGJsb2NrW2ldKXsKICAgICAgICAgICAgICAgICsrY250LCBzdW0gKz0gKGxvdyArIGkpICogMiArIDE7CiAgICAgICAgICAgICAgICBwcmltZXMucHVzaF9iYWNrKChsb3cgKyBpKSAqIDIgKyAxKTsKICAgICAgICAgICAgfQogICAgfTsKfQp2ZWN0b3I8dWludD4gdHJpZzsKdm9pZCBpbml0KCl7Cglmb3IodWludCBpPTE7aTw9MzQ1MDtpKyspewoJCXRyaWcucHVzaF9iYWNrKGkqKGkrMSkvMik7Cgl9Cn0KaW5saW5lIGludCBzY2FuKCkKICAgIHsKICAgICAgICBpbnQgej0wOwogICAgICAgIGNoYXIgYzsKICAgICAgICBkb3sgYz1nZXRjaGFyX3VubG9ja2VkKCk7IH0gd2hpbGUoYzwnMCcpOwogICAgICAgIGZvcig7Yz49JzAnO2M9Z2V0Y2hhcl91bmxvY2tlZCgpKSB6ID0gKHo8PDMpICsgKHo8PDEpICsgKGMmMTUpOwogICAgICAgIHJldHVybiB6OwogICAgfQogaW5saW5lIHZvaWQgZmFzdFdyaXRlKHVuc2lnbmVkIGEsdW5zaWduZWQgYikKewogICAgY2hhciBzbnVtWzMyXTsKICAgIGludCBpPTA7CiAgICBkbwogICAgewogICAgICAgIHNudW1baSsrXT1hJTEwKycwJzsKICAgICAgICBhPWEvMTA7CiAgICB9IHdoaWxlKGEpOwogICAgc251bVtpKytdPScgJzsKICAgICBkbwogICAgewogICAgICAgIHNudW1baSsrXT1iJTEwKycwJz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