#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)

using ll = long long;
const ll INF = 1LL << 60;


int main() {
	string s;
	cin >> s;

	for (int i=0; i<s.size(); i++) {
		if (i%2==0) {
			if (isupper(s[i])) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (islower(s[i])){
				cout << "No "<< endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const string AT = "atcoder";
string S;
char buf[100011];

void MAIN() {
    scanf("%s", buf);
    S = buf;

    int ans = 0;

    if (AT < S) {
	ans = 0;
    } else if (count(S.begin(), S.end(), 'a') == (int)S.size()) {
	ans = -1;
    } else {
	int idx = 0;
	while (S[idx] == 'a') idx++;
	if ('t' < S[idx]) ans = idx - 1;
	else ans = idx;
    }

    printf("%d\n", ans);
}

int main() {
    int TC = 1;
    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

