#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define ll long long int
#define ld long double
#define ba boolalpha
#define F first
#define S second
#define pb push_back
string alphabets = "abcdefghijklmnopqrstuvwxyz";
const long long int mod = 1000000007;
#define loop(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b){
if(b==0){
    return a;
}
return gcd(b,a%b);
}
void solve(){
    ll n;
    cin>>n;
    vector<ll>ans(n);
    loop(i,0,n)cin>>ans[i];
    ll sum = 0 ;
    loop(i,0,n){
     if(ans[i]>10){
         sum+=ans[i]-10;
     }
    }
    cout<<sum<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    solve();
}

#include <bits/stdc++.h>
using namespace std;

#define Fi first
#define Se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)
typedef tuple<int, int, int> t3;

char In[1010];

void solve() {
	scanf("%s", In + 1);
	string s = (string)(In + 1);
	if(s > "atcoder") {
		puts("0");
		return;
	}
	int x = -1, l = (int)strlen(In+1);
	for(int i=1;i<=l;i++) if(In[i] != 'a') {
		x = i; break;
	}
	if(x == -1) puts("-1");
	else {
		char c = In[x];
		if(c > 't') printf("%d\n", x - 2);
		else if(c < 't') printf("%d\n", x - 1);
		else {
			for(int i=x;i>2;i--) swap(In[i], In[i-1]);
			s = (string)(In + 1);
			if(s > "atcoder") printf("%d\n", x - 2);
			else printf("%d\n", x - 1);
		}
	}
}

int main() {
	int T; scanf("%d", &T);
	for(int t=1;t<=T;t++) {
		solve();
	}
	return 0;
}