// COCI-2008 OlympB checker

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include "testlib.h"

using namespace std;

#define VI vector<int>

#define FOR(i,n) for (int i = 0; i < (int)(n); i++)

#define PB push_back
#define SZ(a) a.size()
#define MP make_pair
#define PII pair<int, int>
#define VI vector<int>
#define VVI vector<VI >
#define PII pair<int, int>


int n, res;

vector<int> a;

void swap(int k)
{
	//for (int i = 0; i < n; i++) printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
	if (k < 0 || k > n)
		quitf(_wa, "Illegal swap: %d", k);
	//printf("SWaP %d\n", k);
	for (int i = 0; i < (k + 1)/ 2; i++)
	{
		int t = a[i];
		a[i] = -a[k-i-1];
		a[k-i-1] = -t;
	}
	//for (int i = 0; i < n; i++) printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
}

int main(int argc, char *argv[])
{
	registerTestlibCmd(argc, argv);

	int nt = inf.readInt();

	for (int it = 1; it <= nt; it++)
	{
		a.clear();
		n = inf.readInt();
		for (int i = 0; i < n; i++)
			a.push_back(inf.readInt());
		int it2 = ouf.readInt();
		if (it2 != it)
			quitf(_wa, "Wrong test id: %d, not %d", it2, it);
		res = ouf.readInt();
		if (res < 0 || res > max(3 * n - 2, 0))
			quitf(_wa, "Illegal number of moves: %d, while max = %d", res, max(3 * n - 2, 0));

		for (int i = 0; i < res; i++)
			swap(ouf.readInt());

		for (int i = 0; i < n; i++)
			if (a[i] != i + 1)
				quitf(_wa, "Wrong resulting sequence at position %d = %d", i + 1, a[i]);

	}

	quitf(_ok, "OK %d tests", nt);
}
