#include<bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T &x)
{
x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar())f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c-'0');
x=(f?-x:x);
}
typedef unsigned long long ull;
const int N = 2e5+7;
typedef long long LL;
LL num[N];
int main()
{
// freopen("a.in", "r", stdin);
//freopen("a.ans", "w", stdout);
int t;
read(t);
while(t--)
{
LL n;
read(n);
if(n%4==0)
{
printf("NO\n");
continue;
}
for(int i=0;i<=31;i++)num[i]=0;
printf("YES\n");
for(int i=31;i>=0;i--)
{
LL c=((n>>i)&1);
if(c==1)num[i]=1;
else
{
if(i==0)continue;
int j=i-1;
for(;j&&((n>>j)%2==0);j--);
for(int k=i;k>=j;k--)num[k]=-1;
num[i]=1;
i=j;
}
}
LL x=0;
for(int i=0;i<=31;i++)x+=(1ll<<i)*num[i];
for(int i=0,r=0;i<=31;i++,r=(r+1)%8)
{
printf("%lld ",num[i]);
if(r==7)printf("\n");
}
return 0;
}