#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fr first
#define sc second 
const ll mod = 1e9+7;
const int N = 2e5+5;
void solve(){
	string s; 
	cin>>s; 
	string ss = "atcoder";
	if(ss<s){
		cout<<0<<endl;
		return ;
	}
	int x = -1;
	int n = s.size();
	for(int i=1;i<n;i++){
		if(s[i]!='a'){
			x = i;
			if(s[i]>'t')x--;
			break;
		}
	}
	cout<<x<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	cin>>t; 
	while(t--)solve();
	return 0;
}

#include<stdio.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int Max(size_t a,size_t b){return a>b?(int)a:(int)b;}
int main()
{
  int T;if(!scanf("%d",&T)){return -1;}
  while(T--)
  {
    char S[1001];
    if(!scanf("%s",S)){return -1;}
    if(strncmp("atcoder",S,Max(strlen(S),7))<0){puts("0");continue;}
    else
    {
      if(S[0]=='a'&&S[1]>'a'){puts("1");continue;}
      rep(i,(int)strlen(S)-1)
      {
        if(S[i+1]>'t'){printf("%d\n",i);goto jump;}
        if(S[i+1]>'a'){printf("%d\n",i+1);goto jump;}
      }
      puts("-1");jump:continue;
    }
  }
}