#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
static char buf[1<<21],*p1=buf,*p2=buf;
#define flush() (fwrite(wbuf,1,wp1,stdout),wp1=0)
#define putchar(c) (wp1==wp2&&(flush(),0),wbuf[wp1++]=c)
static char wbuf[1<<21];int wp1;const int wp2=1<<21;
inline int read(void){
	reg char ch=getchar();
	reg int res=0;
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar();
	return res;
}

inline void write(reg int x){
	static char buf[32];
	reg int p=-1;
	if(!x) putchar('0');
	else while(x) buf[++p]=(x%10)^'0',x/=10;
	while(~p) putchar(buf[p--]);
	return;
}

const int MAXN=500;

int n;
int p[MAXN];

int main(void){
	reg int t=read();
	while(t--){
		n=read();
		for(reg int i=0;i<n;++i)
			p[i]=read()-1;
		vector<int> ans;
		for(int i=0;i<n;++i){
			reg int j=find(p,p+n,i)-p;
			if(i!=j){
				if(!((j^ans.size())&1)){
					if(j>=i+2){
						ans.push_back(j-2);
						swap(p[j-2],p[j-1]);
					}
					else{
						ans.push_back(i-1),ans.push_back(i),ans.push_back(i-1),ans.push_back(i),ans.push_back(i-1);
						swap(p[i],p[j]);
						continue;
					}
				}
				for(int k=j-1;k>=i;--k){
					ans.push_back(k);
					swap(p[k],p[k+1]);
				}
			}
		}
		write(ans.size()),putchar('\n');
		if(ans.size())
			for(reg int i=0,siz=ans.size();i<siz;++i)
				write(ans[i]+1),putchar(i==siz-1?'\n':' ');
		else
			putchar('\n');
	}
	flush();
	return 0;
}
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

struct Vector
{
	LLONG x, y;

	Vector()
	{
		x = y = 0;
	}

	Vector(LLONG x, LLONG y) : x(x), y(y) {}

	const Vector operator+(const Vector& rhs) const
	{
		return { x + rhs.x, y + rhs.y };
	}
};

struct Matrix
{
	LLONG a, b, c, d;

	Matrix()
	{
		a = b = c = d = 0;
	}

	Matrix(LLONG a, LLONG b, LLONG c, LLONG d)
		: a(a), b(b), c(c), d(d) {}

	const Matrix operator*(const Matrix& rhs) const
	{
		return { a * rhs.a + b * rhs.c, a * rhs.b + b * rhs.d,
				 c * rhs.a + d * rhs.c, c * rhs.b + d * rhs.d };
	}

	const Vector operator*(const Vector& rhs) const
	{
		return { a * rhs.x + b * rhs.y, c * rhs.x + d * rhs.y };
	}
};

int main()
{
	int N; cin >> N;
	vector<Vector> xs(N);
	REP(i, N)
	{
		LLONG x, y; cin >> x >> y;
		xs[i] = Vector(x, y);
	}
	int M; cin >> M;
	vector<Matrix> ms(M + 1);
	ms[0] = Matrix(1, 0, 0, 1);
	vector<Vector> vs(M + 1);
	REP(i, M)
	{
		int op; cin >> op;
		if (op == 1)
		{
			ms[i + 1] = Matrix(0, 1, -1, 0) * ms[i];
			vs[i + 1] = Matrix(0, 1, -1, 0) * vs[i];
		}
		else if (op == 2) {
			ms[i + 1] = Matrix(0, -1, 1, 0) * ms[i];
			vs[i + 1] = Matrix(0, -1, 1, 0) * vs[i];
		}
		else if (op == 3)
		{
			LLONG p; cin >> p;
			ms[i + 1] = Matrix(-1, 0, 0, 1) * ms[i];
			vs[i + 1] = Matrix(-1, 0, 0, 1) * vs[i] + Vector(2 * p, 0);
		}
		else if(op == 4)
		{
			LLONG p; cin >> p;
			ms[i + 1] = Matrix(1, 0, 0, -1) * ms[i];
			vs[i + 1] = Matrix(1, 0, 0, -1) * vs[i] + Vector(0, 2 * p);
		}
	}
	int Q; cin >> Q;
	REP(i, Q)
	{
		int ai, bi; cin >> ai >> bi; --bi;
		const auto v = ms[ai] * xs[bi] + vs[ai];
		cout << v.x << ' ' << v.y << endl;
	}
}
