#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


const string ATCODER="atcoder";
int main(){
  cout<<setprecision(1000);
  ll T;
  cin>>T;
  For(times,T){
    string S;
    cin>>S;
    if(ATCODER<S){
      cout<<0<<endl;
      continue;
    }
    set<char> s;
    for (auto &&i : S)
    {
      s.insert(i);
    }
    if(s.size()==1&&*s.begin()=='a'){
      cout<<-1<<endl;
      continue;
    }
    if(S[1]>'a'){
      cout<<1<<endl;
      continue;
    }
    ([&S](){
      REP(S.size()){
        if(S[i]>'a'){
          if(S[i]>'t'){
            cout<<i-1<<endl;
            return;
          }else{
            cout<<i<<endl;
            return;
          }
        }
      }
    })();
  }
  return 0;
}

#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 10000000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    string str;
    cin>>str;
    ll n=str.length();
    ll co=0, c_=0, cx=0;
    forr(i, n)
    {
    	if(str[i]=='o') co++;
    	else if(str[i]=='x') cx++;
    	else c_++;
    }
    if(co>4||cx==10)
    {
    	cout<<0<<endl;
    	return;
    }
    ll ans=0;
    vl fact(20, 1);
    forr1(i, 18) fact[i]=(fact[i-1]*i);
    if(co==4)
    {
    	cout<<fact[4]<<endl;
    	return;
    }
    else if(co==3)
    {
    	cout<<3*fact[4]/2+(fact[4]*c_)<<endl;
    }
    else if(co==2)
    {
    	ans+=(14);
    	ans+=(2*c_*fact[4]/2);
    	if(c_>=2)
    	{
    		ans+=(c_*(c_-1)/2)*fact[4];
    		ans+=(c_*fact[4]/2);
    	}
    	else if(c_==1)
    	{
    		ans+=(c_*fact[4]/2);
    	}
    	cout<<ans<<endl;
    }
    else if(co==1)
    {
    	ans=power(c_+1, 4);
    	ans-=power(c_, 4);
    	cout<<ans<<endl;
    	return;
    }
    else
    {
    	cout<<power(c_, 4)<<endl;
    	return;
    }
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}