#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int T,ans,m;
	string S;
	string S0;

	cin >> T ;

	S0="atcoder";

   	rep(k,T) {
		cin >> S;
		ans=-1;
		rep(i,S.size()){
			if ('a'!=S.at(i)){
				ans=i;
				break;
			}
		}
		if (ans<=0){
			cout << ans << endl;
			continue;
		}
		if (ans>1){
			if ('t'<S.at(ans))ans--;
			cout << ans << endl;
			continue;
		}
		if ('t'<S.at(1)){
			cout << 0 << endl;
			continue;
		}
		if ('t'>S.at(1)){
			cout << 1 << endl;
			continue;
		}
		ans=10;
		m=min(S.size(),S0.size());
		rep(i,m){
			if (S.at(i)!=S0.at(i)){
				if(S.at(i)>S0.at(i)) ans=0;
				else ans=1;
			}
		}
		if (ans<2){
			cout << ans << endl;
			continue;
		}
		if (S.size()>S0.size()) ans=0;
		else ans=1;
		cout << ans << endl;
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define T     \
    int t;    \
    cin >> t; \
    while (t--)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define PI 3.141592653589793238462643383
#define pb push_back
#define all(s) s.begin(), s.end()

bool check(string &t) {
    int n = t.length();
    return n >= 3 and (t[n - 1] == 'x' and t[n - 2] == 'o' and t[n - 3] == 'f');
}

int main() {
    fast;
    ll n;
    string s, t = "";
    cin >> n >> s;

    ll cnt = 0;

    for (int i = 0; i < n; i++) {
        t += s[i];
        if (check(t)) {
            t.pop_back();
            t.pop_back();
            t.pop_back();
            cnt++;
        }
    }

    cout << n - (3 * cnt) << endl;
}