#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
vector <int> power;
int arr[32];
int main() {
ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) {
ll num,Z;
int flag = 1;
power.clear();
memset(arr, -1, sizeof(arr));
arr[31] = 1;
cin >> num; Z = num - 1;
if (!num) flag = 0;
for (ll i = 1, j = 0; i <=Z; j++,i=1<<j)
if (Z & i) power.push_back(j);
reverse(power.begin(), power.end());
for (int i = 0; i < power.size()&& flag; i++) {
if (power[i] == 0 && arr[0] != -1) flag = 0;
if (i + 1 < power.size() && power[i] - power[i + 1] == 1) arr[power[i] - 1] = 1;
else if (arr[power[i]] != -1) arr[power[i] - 1] = 1;
else arr[power[i]] = 0;
}
if (flag) {
cout << "YES\n";
for (int i = 0; i < 32; i++)
if ((i + 1) % 8 == 0) cout << arr[i] << "\n";
else cout << arr[i] << " ";
}
else cout << "NO\n";
}
return 0;
}