#include <bits/stdc++.h>

using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
#define endl '\n'


int main() {
#ifdef mlocal
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vi nums(n);
        for_(i, 0, n) cin >> nums[i];
        vi init = nums;

        vi ans;
        for_(m, 0, n * n) {
            bool srt = true;
            for_(i, 0, n-1) if (nums[i] > nums[i+1]) {
                srt = false;
                break;
            }

            if (srt) break;

            for (int i = m % 2; i < n - 1; i += 2) {
                if (i + 2 >= n - 1 or nums[i] > nums[i + 1]) {
                    swap(nums[i], nums[i + 1]);
                    ans.push_back(i + 1);
                    break;
                }
            }
        }


        vi srt = nums;
        sort(srt.begin(), srt.end());
        if (srt != nums) {
            for (auto i: init) cout << i << " ";
            cout << endl;

            cout << "final: ";
            for (auto i: nums) cout << i << " ";
            cout << endl;

            assert(false);
        }

        cout << ans.size() << endl;
        for (auto i: ans) cout << i << " ";
    }
}

#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	string base = "atcoder";
	while(t--){
		string s;
		cin >> s;
		int at = 0, n = s.size();
		while(at < base.size() && at < n && base[at] == s[at]) at++;
		if((at < base.size() && at < n && base[at] < s[at]) || (at == base.size() && at < n)) cout << 0 << '\n';
		else if(at == 1){
			int ans = 1<<30;
			while(at < n && s[at] == 'a') at++;
			if(at == n) ans = -1;
			else {
				if(s[at] > 't') ans = at - 1;
				else ans = at;
			}
			cout << ans << '\n';
		} else {
			assert(at > 1);
			cout << 1 << '\n';
		}
	}
	return 0;
}
