#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define ll long long

int a[200010], b[200010];
ll d[200010];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; ++i) {
        scanf("%d", &b[i]);
    }
    int maxa = a[0];
    d[0] = 1ll*maxa*b[0];
    printf("%lld\n", d[0]);
    for(int i = 1; i < n; ++i) {
        maxa = std::max(maxa, a[i]);
        d[i] = std::max(d[i-1], 1ll*b[i]*maxa);
        printf("%lld\n", d[i]);
    }
    return 0;
}
// Created by Pratik
// NIT PATNA

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;

using namespace std;
#define M                    1000000007
#define pi                   3.14159265358979323846
#define ll                   long long
#define lld                  long double

// Pair
#define pii                  pair<int, int>
#define pll                  pair<ll, ll>

// Vector
#define vl                   vector<ll >
#define vi                   vector<int>
#define vpi                  vector<pii>
#define vpl                  vector<pll>
#define pb                   push_back
#define mp                   make_pair


// Search
#define lb                   lower_bound
#define ub                   upper_bound
#define mina                 *min_element
#define mama                 *max_element
#define bsrch                binary_search

////////
#define F                    first
#define S                    second
#define cel(x,a)             ((x + a - 1) / a)
#define all(v)               v.begin(), v.end()
#define allrev(v)            v.rbegin(), v.rend()
#define lcm(m, n)            ((m / __gcd(m, n))*n)
#define deb(...)             cerr << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__)
#define ms(arr, v)           memset(arr, v, sizeof(arr))
#define ps(x,y)              fixed << setprecision(y) << x
#define _X_                  ios_base::sync_with_stdio(false); cin.tie(NULL)

//pbds
#define ordered                 tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// Input / Output
#define scn(str)             scanf("%s", str)
#define pri(str)             printf("%s\n", str)


const int N = 5e5 + 4;

inline void  dbg()           { cerr << endl; }


template <typename T, typename... V>
inline void  dbg(T t, V... v) {cerr << ' ' << t; dbg(v...);}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool good(int arr[],int n)
{
	for(int i = 1; i<n; i++)if(arr[i]<arr[i-1])return false;
	return true;
}

void solve()
{
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i<n; i++)cin >> arr[i];
	vi ans;
	bool turn = 0;
	while(1)
	{
		if(good(arr,n))break;
		bool used = 0;
		for(int i = n-2; i>=0; i--)
		{
			if(i%2==turn && arr[i]>arr[i+1])
			{
				ans.pb(i+1);
				swap(arr[i],arr[i+1]);
				used = 1;
				break;
			}
		}
		if(!used)
		{
			swap(arr[turn],arr[turn+1]);
			ans.pb(turn+1);
		}
		turn = !turn;
		//deb(turn);
	}
	int k = ans.size();
	assert(k<=n*n);
	cout << ans.size() << "\n";
	for(int &i:ans)cout << i << " ";
	cout << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    // clock_t time_req = clock();
    int t = 1;
     cin>> t;
    while (t--) {
       solve();



   }


    // time_req = clock() - time_req;
    // cout << (float)time_req / CLOCKS_PER_SEC;
   return 0;
}
