//* Problem  : R - Railway Transportation
//* Origin   : CTU - 2007
//* Type     : Judge
//* Date     : 2009.04.20
//* 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;

#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()

int n, m;

VI a, rr;

vector <vector<int> > r;

vector <int> idx;

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


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

	int nt = 0;

	while (1)
	{
		n = inf.readInt();
		m = inf.readInt();
		if (n == 0 && m == 0) break;
		nt++;
		a.clear();
		FOR(i,n)
			a.push_back(inf.readInt());
		string et = ans.readString();
		if (et == "Transportation failed")
		{
			string an = ouf.readString();
			if (an != et)
			{
				quitf(_wa, "Test #%d. Expected 'Transportation failed', found: '%s'", nt, an.c_str());
			}
		}
		else
		{
			r.assign(m + 1, VI());
			idx.assign(m + 1, 0);
			ans.readString();
			vector <int> to = parse_str(ouf.readString());
			if (to.size() != n)
				quitf(_wa, "Test #%d. Wrong answer vector size: %d instead of %d", nt, to.size(), n);
			FOR(i,n)
			{
				if (to[i] < 1 || to[i] > m)
					quitf(_wa, "Test #%d. Wrong index: %d, while m = %d", nt, to[i], m);
				if (r[to[i]].size() && r[to[i]][r[to[i]].size() - 1] > a[i])
					quitf(_wa, "Test #%d. Cannot put here", nt, to[i], m);
				r[to[i]].PB(a[i]);
			}
			rr.clear();
			to = parse_str(ouf.readString());
			if (to.size() != n)
				quitf(_wa, "Test #%d. Wrong answer vector size: %d instead of %d", nt, to.size(), n);
			FOR(i, n)
			{
				if (to[i] < 1 || to[i] > m)
					quitf(_wa, "Test #%d. Wrong index: %d, while m = %d", nt, to[i], m);
				if (idx[to[i]] >= SZ(r[to[i]]))
					quitf(_wa, "Test #%d. Track is empry", nt);
				rr.push_back(r[to[i]][idx[to[i]]++]);
			}
			sort(a.begin(), a.end());
			FOR(i,n)
				if (a[i] != rr[i])
					quitf(_wa, "Test #%d. Wrong sequence %d != %d", nt, a[i], rr[i]);
		}
	}
	quitf(_ok, "OK %d tests", nt);
}
