//* Problem  : C - Calendar of Events
//* Origin   : CTU - 2007
//* Type     : Judge
//* Date     : 2009.04.05
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 9.0

#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;

int n;

vector <int> a, r, rr;

vector <int> parse_str(string s)
{
	vector <int> res;
	const char *p = s.c_str();
	while (*p)
	{
		while (*p && (*p > '9' || *p < '0')) p++;
		if (!*p) break;
		int t = 0;
		while (!(*p > '9' || *p < '0'))
		{
			t = 10 * t + *p++ - '0';
		}
		res.push_back(t);
	}
	return res;
}

void reverse(vector <int> &a, int k)
{
	reverse(a.begin(), a.begin() + k);
}

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

	int nt = 0;

	while (!ans.eof())
	{
		a.clear();
		r.clear();
		n = inf.readInt();
		if (ans.readString() == "") break;
		for (int i = 0; i < n; i++)
			a.push_back(inf.readInt());
		for (int i = 0; i < n; i++)
			r.push_back(inf.readInt());
		rr = parse_str(ouf.readString());
		if (rr.size() > 52)
			quitf(_wa, "Too much operations: %d", rr.size());
		for (int i = 0; i < rr.size(); i++)
		{
			if (rr[i] < 1 || rr[i] > n)
				quitf(_wa, "Wrong index %d", rr[i]);
			reverse(a, rr[i]);
		}
		nt++;
		//printf("%d\n", nt);
		for (int i = 0; i < n; i++)
			if (a[i] != r[i])
				quitf(_wa, "Wrong sequence %d\n", i);
	}
	quitf(_ok, "OK %d tests", nt);
}
