#pragma region
//#pragma optimize("Ofast")
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, a, n) for (int i = n; i >= a; --i)
#pragma endregion
const int maxn = 2e5 + 5;
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    m *= 100;
    rep(i, 1, n) {
        int x, y;
        scanf("%d%d", &x, &y);
        m -= x * y;
        if (m < 0) {
            printf("%d\n", i);
            return 0;
        }
    }
    puts("-1");
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plp;
typedef pair<pll,ll> ppl;
typedef pair<pll,pll> ppp;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pll> vpll;
typedef vector<plp> vplp;
typedef vector<ppl> vppl;
typedef vector<ppp> vppp;
typedef vector<vpll> vvpll;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<double> vd;
typedef priority_queue<pll,vpll,greater<pll> > pqpll;
typedef priority_queue<pll,vpll> pqrpll;
typedef priority_queue<ll, vll, greater<ll> > pqll;
typedef priority_queue<ll, vll> pqrll;

struct edge{ ll to,cost; edge(ll to,ll cost): to(to), cost(cost){} };
typedef vector<vector<edge>> Graph;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF 1000000000000000000
#define INF 1000000000
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) a.begin(), a.end()

template<typename T> ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 

void chmin(ll &a, ll &b) { if(a > b) a = b; }
void chmax(ll &a, ll &b) { if(a < b) a = b; }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1};
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

int main(){
    ll t;
    cin >> t;
    rep(i,0,t){
        string s,t;
        cin >> s;
        string memo = "atcoder";

        t = s;
        sort(ALL(t),greater<char>());
        
        if(memo < s) cout << 0 << endl;
        else if(memo >= t) cout << -1 << endl;
        else{
            ll ans = LINF;
            rep(i,0,sz(memo)){
                rep(j,i,sz(s)){
                    if(s[j] > memo[i]){
                        ans = min(ans,j-i);
                        break;
                    }
                }
                if(s[i] < memo[i]) break;
            }
            rep(i,0,sz(s)) if(s[i] != 'a') {ans = min(ans,i); break;}
            cout << ans << endl;
        }
    }

    return 0;
}