#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;
typedef unsigned long long hsh;

using namespace std;

int ts;
string s, t = "atcoder";

void inline solve() {
	cin >> s;
	if (t < s) {
		cout << 0 << ln;
		return;
	}
	int p = -1;
	loop (i, s.size()) {
		if (s[i] != 'a') {
			p = i;
			break;
		}
	}
	if (p == -1) {
		cout << -1 << ln;
		return;
	}
	cout << p - (s[p] > 't') << ln;
}

int main() {
	ios::sync_with_stdio(0);
	cin >> ts;
	cont (cs, ts) {
		solve();
	}
}
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n,m;
    cin >> n >> m;
    if (0 <= m && m < n-1) {
        int x = (n-1-m-1)*2+1,c = 1;
        for (int i = 0;i < n-1;++i) {
            if (x == c) c++;
            cout << c << " " << c+1 << newl;
            c += 2;
        }
        cout << x << " " << 2*n << newl;
    } else if (n == 1 && m == 0) {
        cout << "1 2\n";
    } else {
        cout << -1 << newl;
    }
}