#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    vector<int> ans;
    int pr = -1;
    auto transpose = [&ans, &pr, &a](int i) {
      swap(a[i], a[i + 1]);
      if (pr == -1) {
        pr = i;
        return;
      }
      if (i == pr - 1)
        ans.push_back(i);
      else
        for (int j = min(i, pr); j < max(i, pr); j++) {
          ans.push_back(j);
          ans.push_back(j);
        }
      pr = -1;
    };
    for (int i = 0; i < n; i++)
      for (int j = 0; j + i + 1 < n; j++)
        if (a[j] > a[j + 1]) transpose(j);
    if (pr != -1)
      for (int i = 0; i + 1 < n; i++)
        if (a[i] == a[i + 1]) {
          transpose(i);
          break;
        }
    if (pr != -1)
      printf("-1\n");
    else {
      assert(ans.size() <= n * n);
      printf("%d\n", ans.size());
      for (int i = 0; i < ans.size(); i++) {
        if (i) printf(" ");
        printf("%d", ans[i] + 1);
      }
      printf("\n");
    }
  }
}
