#include <bits/stdc++.h>
using namespace std;
ifstream fi("dayso.inp");
ofstream fo("sohh.out");
long int a[10000],t,n;
int tonguoc(long int n){
    int t=1;
    if (n==1){return 0;}
    else {for(long int i=2;i<=n/2;i++)
{
    if(n%i==0)
    {t=t+i;}}
    if (t==n){return 1;}
    else {return 0;}
    }
}
int main()
{
    fi>>n;
    for(long int i=1;i<=n;i++)
    {
        fi>>a[i];
    }
    for(long int i=1;i<=n;i++)
    {
    if(tonguoc(a[i])==1)
    {
    fo<<a[i]<<endl;
    }}
}
