#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(b-1)),y(up?b:(a-1)){}_RX(int a):_RX(0,a){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

bool iseven(int x) {
	return (x & 1) == 0;
}

void oesort3(vector<int>& xs, int pos, bool even, vector<int>& ops) {

	int retry = 0;

	auto check = [&]() {
		for(auto i : range(3)) {
			if(xs[pos + i] != pos + i) {
				return false;
			}
		}
		return true;
	};

	while(!check()) {

		int p = (iseven(pos) == even) ? pos : pos + 1;
		ops.push_back(p);
		swap(xs[p], xs[p + 1]);
		even = !even;

		retry += 1;
		assert(retry < 100);
	}
}

void oesort(vector<int>& xs, int pos, bool even, vector<int>& ops) {

	const int N = xs.size();

	if(N - pos == 3) {
		return oesort3(xs, pos, even, ops);
	}

	assert(N - pos >= 4);

	int target = pos;
	while(xs[target] != pos) {
		target += 1;
	}

	if(target == pos) {
		oesort(xs, pos + 1, even, ops);
		return;
	}

	int retry = 0;

	while(iseven(target - 1) != even) {
		if(target - 2 >= pos) {
			ops.push_back(target - 2);
			swap(xs[target - 2], xs[target - 1]);
			even = !even;
		} else {
			ops.push_back(target);
			swap(xs[target], xs[target + 1]);
			target += 1;
			even = !even;
		}
		retry += 1;
		assert(retry < 100);
	}

	for(auto i : revrange(pos, target)) {
		assert(iseven(i) == even);
		ops.push_back(i);
		swap(xs[i], xs[i + 1]);
		even = !even;
	}

	oesort(xs, pos + 1, even, ops);
}

void solve() {

	const int N = read_item();
	vector<int> As(N);
	for(auto i : range(N)) {
		As[i] = (int)read_item() - 1;
	}

	if(N == 2) {
		if(As[0] == 0) {
			printf("0\n");
			return;
		} else {
			printf("1\n1\n");
			return;
		}
	}

	static vector<int> ops;
	ops.resize(0);

	oesort(As, 0, true, ops);
	int c = ops.size();

	assert(c <= N * N);
	printf("%d\n", c);
	for(auto i : range(c)) {
		printf("%d%c", ops[i] + 1, splf(i, c));
	}

}

int main() {

	const int T = read_item();
	for(auto _ : range(T)) {
		solve();
	}

	return 0;
}

/* wafdayo~~~ */

/*
 * author: cyclexit
 * start from: 2021-01-25 16:23
 */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

template<typename T>
struct Point {
  T x, y;
};

template<typename T>
struct Plane {
  array<T, 3> unitx{1, 0, 0};
  array<T, 3> unity{0, 1, 0};
};

template<typename T>
inline Plane<T> rotate90(Plane<T> p) {
  swap(p.unitx, p.unity);
  for (int i = 0; i < 3; ++i) {
    p.unity[i] *= -1;
  }
  return p;
}

template<typename T>
inline Plane<T> rotate270(Plane<T> p) {
  swap(p.unitx, p.unity);
  for (int i = 0; i < 3; ++i) {
    p.unitx[i] *= -1;
  }
  return p;
}

template<typename T>
inline Plane<T> symmetric_x(Plane<T> p, T x) {
  for (int i = 0; i < 3; ++i) {
    p.unitx[i] *= -1;
  }
  p.unitx[2] += 2 * x;
  return p;
}

template<typename T>
inline Plane<T> symmetric_y(Plane<T> p, T y) {
  for (int i = 0; i < 3; ++i) {
    p.unity[i] *= -1;
  }
  p.unity[2] += 2 * y;
  return p;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<Point<ll>> points(n);
  for (int i = 0; i < n; ++i) {
    cin >> points[i].x >> points[i].y;
  }
  int m;
  cin >> m;
  vector<Plane<ll>> planes(m + 1);
  ll op, v;
  for (int i = 1; i <= m; ++i) {
    cin >> op;
    switch (op) {
      case 1:
        planes[i] = rotate90(planes[i - 1]);
        break;
      case 2:
        planes[i] = rotate270(planes[i - 1]);
        break;
      case 3:
        cin >> v;
        planes[i] = symmetric_x(planes[i - 1], v);
        break;
      case 4:
        cin >> v;
        planes[i] = symmetric_y(planes[i - 1], v);
        break;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    --b;
    auto unitx = planes[a].unitx;
    auto unity = planes[a].unity;
    ll x = unitx[0] * points[b].x + unitx[1] * points[b].y + unitx[2];
    ll y = unity[0] * points[b].x + unity[1] * points[b].y + unity[2];
    cout << x << " " << y << '\n';
  }
  return 0;
}