#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
const int N=500500;
int read(int &n)
{
	bool q=0;n=0;char ch=' ';
	for(;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
	if(ch=='-')ch=getchar(),q=1;
	for(;ch>='0'&&ch<='9';ch=getchar())n=(n<<3)+(n<<1)+ch-48;
	return q?n=-n:n;
}
int n,m;
int a[N],a0[N];
int Ans[N];
int JS(int q,int w,int i,int j)
{
	return abs(q-i)+abs(w-j);
}

int main()
{
	int q,w,_;
	read(_);
	while(_--)
	{
		read(n);
		fo(i,1,n)read(a[i]),a0[i]=a[i];
		Ans[0]=0;
		
		fo(I,1,n)
		{
			int nw;
			fo(i,1,n)if(a[i]==I){nw=i;break;}
			if(nw==I)continue;
			if(((nw-1)&1)==(Ans[0]&1))
			{
				fod(i,n-1,1)if((i&1)!=(Ans[0]&1)){q=i;break;}
				if(q==nw)
				{
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					Ans[++Ans[0]]=q-1,swap(a[q],a[q-1]);
					++nw;
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
				}else if(q<I)
				{
					fo(i,1,n)if((i&1)!=(Ans[0]&1)){q=i;break;}
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
					if(q%2!=Ans[0]%2)
					{
						Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					}else{
						Ans[++Ans[0]]=q+3,swap(a[q+3],a[q+4]);
						Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
						Ans[++Ans[0]]=q+3,swap(a[q+3],a[q+4]);
						
					}

				}
				else{
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
				}
			}else{
				fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
			}
		}


		// fo(i,1,Ans[0])
		// {
		// 	q=Ans[i];
		// 	if(Ans[i]%2 !=(i&1))printf("dfwefwefe\n");
		// 	swap(a0[q],a0[q+1]);
		// }
		// fo(i,1,n-1)if(a0[i]>a0[i+1])printf("wefverbrtbrtbrterth\n");
		printf("%d\n",Ans[0]);
		fo(i,1,Ans[0])printf("%d ",Ans[i]);printf("\n");
	}




	return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define deb(x) cout << #x": " << (x) << endl;

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

lli poww(lli a, lli b, lli mod){
	lli res =1;
	while(b){ if(b&1) res = (res * a)%mod; a = (a*a)%mod; b/=2; }
	return res;
}

vvc<int> graph(int n, int m, bool dir=1){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		if(dir)v[b].pb(a);
	}
	return v;
}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- コーディングはここから！ ('-')7
void solve(){
	int n; cin>>n;
	vc<lli>v(n),x(n),y(n);
	fore(i,0,n)cin>>x[i];
	fore(i,0,n)cin>>y[i];
	v[0]=x[0];
	fore(i,1,n)v[i]=max(x[i],v[i-1]);
	v[0]*=y[0];
	fore(i,1,n)v[i]=max(v[i-1],v[i]*y[i]);
	fore(i,0,n)cout<<v[i]<<ENDL;

//	cout<<ENDL;

}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}
