#include <bits/stdc++.h>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define PB push_back
#define MK make_pair
using namespace std;
#define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl

const int maxn = 5000 + 5;
const int modu = 998244353; // 1e9 + 7
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

typedef long long LL;

void read(LL &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9')  {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}

void read(int &x) { LL y; read(y); x = (int)y; }
void read(char &ch) { char s[3]; scanf("%s", s); ch = s[0]; }
void read(char *s) { scanf("%s", s); }
template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); }

int n, m;
int a[maxn];
LL inv[maxn], c[maxn], f[20][maxn];
int b[20];

int main() {
    // freopen("my.txt", "w", stdout);
    read(n, m);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i)
        inv[i] = (modu - (modu/i))*inv[modu%i]%modu;
    c[0] = 1;
    for (int i = 1; i <= n; ++i)
        c[i] = (n-i+1)*inv[i]%modu*c[i-1]%modu;
    int nb = 0;
    while (m) {
        b[nb++] = m%2;
        m /= 2;
    }
    memset(f, 0, sizeof(f));
    f[nb-1][0] = 1;
    int tot = b[nb-1];
    for (int i = nb-2; i >= 0; --i) {
        for (int j = 0; j <= tot*2 + b[i]; ++j) if (j%2 == 0) {
            for (int k = 0; k <= j && k <= n; k += 2)
                f[i][j] = (f[i][j] + f[i+1][(j-k)/2]*c[k]) % modu;
        }
        tot = tot*2 + b[i];
    }
    printf("%lld\n", f[0][tot]);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int n;

int a[505];

int ans[250005],len;

int p=1;

void doSwap(int pos) {
	if(p%2==1) {
		int x=rand()%2;
		if(2*x+1==pos || 2*x+2==pos) {
			x^=1;
		}
		swap(a[2*x+1],a[2*x+2]);
		ans[++len]=2*x+1;
		p++;
	}else {
		if(pos==2 || pos==3) {
			swap(a[4],a[5]);
			ans[++len]=4;
			p++;
		}else {
			swap(a[2],a[3]);
			ans[++len]=2;
			p++;
		}
	}
}

void sortSwap4() {
	if(a[4]==4) {
		return;
	}
	int pos=0;
	for(int j=1;j<=4;j++) {
		if(a[j]==4) {
			pos=j;
			break;
		}
	}
	if(pos==1) {
		if(p%2==0) {
			swap(a[2],a[3]);
			ans[++len]=2;
			p++;
		}
		swap(a[1],a[2]);
		ans[++len]=1;
		swap(a[2],a[3]);
		ans[++len]=2;
		swap(a[3],a[4]);
		ans[++len]=3;
		p++;
	}else if(pos==2) {
		if(p%2==1) {
			swap(a[3],a[4]);
			ans[++len]=3;
			p++;
		}
		swap(a[2],a[3]);
		ans[++len]=2;
		swap(a[3],a[4]);
		ans[++len]=3;
	}else if(pos==3) {
		if(p%2==0) {
			swap(a[2],a[3]);
			ans[++len]=2;
			swap(a[3],a[4]);
			ans[++len]=3;
			swap(a[2],a[3]);
			ans[++len]=2;
			swap(a[3],a[4]);
			ans[++len]=3;
		}else {
			swap(a[3],a[4]);
			ans[++len]=3;
			p++;
		}
	}
}

int main() {
	srand(time(0));
	int T;
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		for(int i=1;i<=n;i++) {
			scanf("%d",&a[i]);
		}
		if(n==2) {
			if(a[1]!=1) {
				swap(a[1],a[2]);
				printf("1\n1\n");
			}else {
				printf("0\n\n");
			}
			continue;
		}
		len=0;
		p=1;
		for(int i=n;i>=5;i--) {
			int pos=0;
			for(int j=1;j<=n;j++) {
				if(a[j]==i) {
					pos=j;
					break;
				}
			}
			if((pos%2==0 && p%2==1) || (pos%2==1 && p%2==0)) {
				doSwap(pos);
			}
			//printf("Value at position %d: %d\n",pos,a[pos]);
			for(int j=pos;j<i;j++) {
				swap(a[j],a[j+1]);
				ans[++len]=j;
				p++;
			}
			//printf("Stage 1 level %d: ",i);
		}
		//Sort 1-4
		if(n>=4) {
			sortSwap4();
		}
		//Sort 1-3
		while(a[1]!=1 || a[2]!=2 || a[3]!=3) {
			if(p%2==1) {
				swap(a[1],a[2]);
				ans[++len]=1;
				p++;
			}else {
				swap(a[2],a[3]);
				ans[++len]=2;
				p++;
			}
		}
		printf("%d\n",len);
		for(int i=1;i<=len;i++) {
			printf("%d ",ans[i]);
		}
		printf("\n");
	}
	return 0;
}