#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int T, n;
int a[40], cnt = 0;
void Apply(int x, int l, int r) {
a[l] = x; for (int i = l + 1; i <= r; ++i) a[i] = -x;
}
void Work(int nn) {
n = nn;
int y = n;
cnt = 0, memset(a, 0, sizeof(a));
while (y) a[++cnt] = y % 2, y >>= 1;
cnt = 32;
reverse(a + 1, a + cnt + 1);
int conti = 0, l = 1, r;
for (int i = 1; i <= cnt; ++i) {
if (a[i] == 0) ++conti, (conti == 1 ? l = r = i : r = i);
if (a[i] != 0 && conti > 1) Apply(a[i], l, r), a[i] = -a[i], conti = 0;
if (a[i] != 0) l = r = i + 1;
}
if (conti > 1) return puts("NO"), void();
puts("YES");
reverse(a + 1, a + cnt + 1);
int sum = 0;
for (int i = 1; i <= cnt; ++i)
printf("%d%c", a[i], i%8!=0?' ':'\n');
// cout << sum << endl;
// if (sum != n) { puts("114514"); exit(0);}
}
int main() {
cin >> T; while (T --) Work();
// for (int i = 1; i <= 1000; ++i) Work(i);
// Work(0);
return 0;
}
/*
11
0
1
2
3
4
5
6
7
8
9
10
*/