#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

string x="atcoder";

void solve(){
    string s;
    cin>>s;
    //cerr<<string(s.size(),'a')<<endl;;
    if(s>x){
        cout<<0<<endl;
        return ;
    }
   if(s==string(s.size(),'a')){
       cout<<-1<<endl;
   }
   else{
      for (int i = 0; i < s.size(); i++)
      {
          if(s[i]!='a'){
              if(s[i]>'t'){
                  cout<<i-1<<endl;
              }
              else{
                  cout<<i<<endl;
              }
              return ;
          }
      }
      
   }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main(){
  int T, ans, howlong;
  string S, Spoint, comppoint;
  cin >> T;
  for(int i = 0; i < T; i++){
    cin >> S;
    howlong = S.size();
    if("atcoder" < S){
      ans = 0;
    }else{
      for(int j = 0; j < howlong; j ++){
        Spoint = S.at(j);
        if("t" < Spoint){
          ans = j - 1;
          break;
        }if("a" < Spoint){
          ans = j;
          break;
        }else{
          ans = -1;
        }
      }
    }
  cout << ans << endl;
  }
}