#include<bits/stdc++.h>
#define rint register int 
#define ll long long 
using namespace std;
int T;
string s="atcoder";
string S; 
int main(){
	cin>>T;
	while(T--) {
		cin>>S;
		int len=S.length();
		int ans=-1;
		for(rint i=0;i<len;++i){
			if(S[i]!='a') {ans=i;break;}
		}
		if(S>s) {
			cout<<0<<"\n";
			continue;
		}
		if(ans==-1) {
			cout<<-1<<'\n'; 
		}
		else {
			if(S[ans]>'t') ans--;
			cout<<ans<<'\n'; 
		}
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int C(int n,int r)
{
    int ans=1;

    for(int i=1;i<=r;i++)
    {
        ans*=n--;
        ans/=i;
    }
    return ans;
}

bool valid(int n,auto &c,auto &t)
{
    set<int> cused;

    for(int i=0;i<4;i++)
    {
        int cur= n%10;
        n/=10;

        if(c.count(cur))
        {
            cused.insert(cur);
        }
        else if(t.count(cur))
        {

        }
        else
        {
            return false;
        }
    }

    return cused==c;
}

void solve()
{
    string str;
    cin>>str;

    set<int> contained,ns;

    for(int i=0;i<10;i++)
    {
        if(str[i]=='o') contained.insert(i);
        else if(str[i]=='?') ns.insert(i);
    }
    int ans=0;
    for(int i=0;i<=9999;i++)
    {
        if(valid(i,contained,ns)) ans++;
    }

    cout<<ans;
}
 
int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}