#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,sum=0;cin>>n;int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        //sum+=a[i]+b[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i<n;i++)
    {
        long long m=0;
        m=a[i]*b[i];
        sum+=m;
    }
    if(sum==0)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
typedef pair<int, int> P;
int main()
{
    int T;
    cin >> T;
    string cp = "atcoder";
    while (T--) {
        string S;
        cin >> S;
        if (S > cp) {
            cout << 0 << endl;
            continue;
        }
        ll ans = INF;
        repd(i, 1, S.size()) {
            if (S[i] > 'a') {
                chmin(ans, i);
                break;
            }
        }
        repd(i, 2, S.size()) {
            if (S[i] > 't') {
                chmin(ans, i - 1);
                break;
            }
        }

        if (ans == INF) ans = -1;
        cout << ans << endl;
    }
    return 0;
}