#include<bits/stdc++.h>
using namespace std;
int n,h;
bool o[43000002];
int u;
int main(){
cin>>n;
o[1]=false;
for(int i=2;i<=1000001;i++){
o[i]=true;
}
for(int i=2;i<=1000001;i++){
if(o[i]==true){
for(int j=i;j<=n/i;j++){
o[i*j]=false;
}
}
}
for(int i=0;i<n;i++){
cin>>u;
for(int j=1;j<=u-1;j++){
if(o[n^j]==true) {
h++;
cout<<(n^j)<<' ';
}
}
cout<<h<<"\n";
h=0;
}
}