#include <bits/stdc++.h>

using namespace std;

ifstream fi ("dayso.inp");
ofstream fo ("SOHH.OUT");

bool testhh(int a)
{   int i=0,t=1;
    if (a==1){return false;}
    else {
        for (i=2;i<=a/2;i++){
            if (a%i==0){t=t+i;}
        }
        if (t==a){return true;}
        else return false;
    }
}

int main(){
  int n;
  fi>>n;
  int a[n],i=0;
  for (i=0;i<n;i++){ fi >> a[i];}
  for (i=0;i<n;i++){
    if (testhh(a[i])==true){fo<<a[i]<<endl;}
  }
}

