#include<ctime>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<algorithm>
#define ll long long
using namespace std;
const double k=(sqrt(5)-1)/2;
const double t=k;
ll read(){
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while(isdigit(c)){
		x=x*10+f*(c-48);
		c=getchar();
	}
	return x;
}
ll n,x,y,cnt,ans[1000];
void solve(){
	if(n==1){
		puts("1");
		puts("1");
		return;
	}
	ans[1]=3;
	for(ll i=max(0ll,(ll)(k*n-1000000));i<=min(n,(ll)(k*n+1000000));++i){
		x=i;
		cnt=1;
		y=n-x;
		while(x>=1&&y>=1){
			if(cnt>130)
				break;
			if(x>y){
				ans[++cnt]=3;
				x-=y;
			}
			else{
				ans[++cnt]=4;
				y-=x;
			}
		}
		while(x){
			if(cnt>130)
				break;
			--x;
			ans[++cnt]=1;
		}
		while(y){
			if(cnt>130)
				break;
			--y;
			ans[++cnt]=2;
		}
		if(cnt<=130)
			break;
	}
	printf("%lld\n",cnt);
	for(ll i=cnt;i;--i)
		printf("%lld\n",ans[i]);
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	solve();
	//--------
	fprintf(stderr,"%0.3lfs",1.0*(clock()-t1)/CLOCKS_PER_SEC);
	return 0;
}
#include <bits/stdc++.h>
#define REP(x, a) for(int x=0; x<a; x++)
#define sz(x) (int) (x).size()

using namespace std;

int _;

void solve() {
	string s;
	cin >> s;
	int n = sz(s);
	if (s > "atcoder") {
		cout << 0 << '\n';
		return;
	}
	int pos = -1;
	REP(i, n) {
		if (s[i] != 'a') {
			pos = i;
			break;
		}
	}
	if (pos == -1) {
		cout << -1 << '\n';
		return;
	}
	if (s[pos] > 't') cout << pos - 1 << '\n';
	else cout << pos << '\n';
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (cin >> _; _; --_) solve();
	return 0;
 }