import java.util.*;
public class vaihdot {
public static int find(int[] a, int target)
{
for (int i = 0; i < a.length; i++)
if (a[i] == target)
return i;
return -1;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
int[] ans = new int[t];
int[][][] ans2 = new int[t][500][2];
int a = 0;
int b = 0;
for (int t1 = 0; t1 < t; t1++) {
int n = input.nextInt();
int[] elem = new int[n];
int[] indOf = new int[n+1];
for (int n1 = 0; n1 < n; n1++) {
a = input.nextInt();
elem[n1] = a;
indOf[a] = n1;
}
ans[t1] = 0;
if (n == 1) {
continue;
}
if (n == 2) {
if (elem[0] == 2) ans[t1] = -1;
continue;
}
if (n == 3) {
if (elem[1] != 2) {ans[t1] = -1;}
else if (elem[0] == 3) {
ans[t1] = 1;
ans2[t1][0][0] = 1;
ans2[t1][0][1] = 3;
}
continue;
}
// n > 3
int swaps = 0;
int ind1 = 0;
int ind2 = 0;
if (n == 4) {
ans[t1] = 0;
if (elem[1] != 2) {
if (indOf[2] == 2) {
a = elem[0];
elem[0] = 2;
elem[2] = a;
indOf[2] = 0;
indOf[a] = 2;
ans2[t1][swaps][0] = 1;
ans2[t1][swaps][1] = 3;
swaps++;
ans[t1]++;
}
if (indOf[2] == 0) {
a = elem[3];
elem[3] = 2;
elem[0] = a;
indOf[2] = 3;
indOf[a] = 0;
ans2[t1][swaps][0] = 1;
ans2[t1][swaps][1] = 4;
swaps++;
ans[t1]++;
}
if (indOf[2] == 3) {
a = elem[1];
elem[1] = 2;
elem[3] = a;
indOf[2] = 1;
indOf[a] = 3;
ans2[t1][swaps][0] = 2;
ans2[t1][swaps][1] = 4;
swaps++;
ans[t1]++;
}
}
if (elem[2] != 3) {
if (indOf[3] == 3) {
a = elem[0];
elem[0] = 3;
elem[3] = a;
indOf[3] = 0;
indOf[a] = 3;
ans2[t1][swaps][0] = 1;
ans2[t1][swaps][1] = 4;
swaps++;
ans[t1]++;
}
if (indOf[3] == 0) {
a = elem[2];
elem[2] = 3;
elem[0] = a;
indOf[3] = 2;
indOf[a] = 0;
ans2[t1][swaps][0] = 1;
ans2[t1][swaps][1] = 3;
swaps++;
ans[t1]++;
}
}
if (elem[0] != 1) {
a = elem[0];
elem[0] = 1;
elem[3] = a;
indOf[1] = 0;
indOf[a] = 3;
ans2[t1][swaps][0] = 1;
ans2[t1][swaps][1] = 4;
swaps++;
ans[t1]++;
}
continue;
}
// n > 4
// parittomat ja parilliset kohdilleen
for (int k = 0; k < n; k++) {
ind1 = k;
a = elem[ind1];
if (((elem[k]+k) % 2) == 0) {
for (int k2 = k+2; k2 < n; k2++) {
ind2 = k2;
b = elem[ind2];
if (((a+b) % 2) == 1) {
elem[ind1] = b;
elem[ind2] = a;
indOf[b] = ind1;
indOf[a] = ind2;
ans2[t1][swaps][0] = ind1+1;
ans2[t1][swaps][1] = ind2+1;
swaps++;
ans[t1]++;
break;
}
}
}
}
// tarkista kaksi viimeista
if (((elem[n-2]+n) % 2) == 0) {
ind1 = n-4;
a = elem[ind1];
ind2 = n-2;
b = elem[ind2];
elem[ind1] = b;
elem[ind2] = a;
indOf[b] = ind1;
indOf[a] = ind2;
ans2[t1][swaps][0] = ind1+1;
ans2[t1][swaps][1] = ind2+1;
swaps++;
ans[t1]++;
ind1 = n-4;
a = elem[ind1];
ind2 = n-1;
b = elem[ind2];
elem[ind1] = b;
elem[ind2] = a;
indOf[b] = ind1;
indOf[a] = ind2;
ans2[t1][swaps][0] = ind1+1;
ans2[t1][swaps][1] = ind2+1;
swaps++;
ans[t1]++;
}
// nyt vaihdot kohdilleen
for (int k3 = 0; k3 < n; k3++) {
if (elem[k3] != (k3+1)) {
ind1 = k3;
a = elem[ind1];
ind2 = indOf[k3+1];
b = elem[ind2];
elem[ind1] = b;
elem[ind2] = a;
indOf[b] = ind1;
indOf[a] = ind2;
ans2[t1][swaps][0] = ind1+1;
ans2[t1][swaps][1] = ind2+1;
swaps++;
ans[t1]++;
}
} // vaihdot ok
} // t1
for (int i = 0; i < t; i++) {
System.out.println(ans[i]);
if (ans[i] > 0) {
for (int k = 0; k < ans[i]; k++) {
System.out.print(ans2[i][k][0] + " ");
System.out.println(ans2[i][k][1]);
}
}
}
input.close();
}
}