// COCI-2007 3F 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, k;

#define MAXL 500000

struct list_item {
	int L, R, val;
} a[MAXL + 2];

void swap(char c, int x, int y, bool fCheck)
{
	if (fCheck)
	{
		if (x < 1 || x > n || y < 1 || y > n || (c != 'A' && c != 'B'))
			quitf(_wa, "Wrong operation %c %d %d", c, x, y);
	}

	// izbaci x iz liste
	a[a[x].R].L = a[x].L;
	a[a[x].L].R = a[x].R;

	// odredi nove susjede cvoru x
	if (c == 'A')
	{
		a[x].L = a[y].L;
		a[x].R = y;
	}
	else
	{
		a[x].L = y;
		a[x].R = a[y].R;
	}

	// ubaci x u listu
	a[a[x].R].L = x;
	a[a[x].L].R = x;
}

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

	n = inf.readInt();
	k = inf.readInt();

	res = ans.readInt();

	int k_out = ouf.readInt();
	if (k_out != res)
		quitf(_wa, "Wrong number of moves. Expected %d, got %d", res, k_out);

	for (int i = 0; i <= n; i++)
	{
		a[i].val = i;
		a[i].L = i - 1;
		a[i].R = i + 1;
	}

	for (int i = 0; i < k; i++)
	{
		char c = inf.readWord()[0];
		int x = inf.readInt();
		int y = inf.readInt();

		swap(c, x, y, false);
	}

	for (int i = 0; i < res; i++)
	{
		char c = ouf.readWord()[0];
		int x = ouf.readInt();
		int y = ouf.readInt();

		swap(c, x, y, true);
	}

	for (int i = 1; i <= n; i++)
	{
		if (a[i].L != i - 1 || a[i].R != i + 1)
			quitf(_wa, "Wrong subsequence %d %d %d", a[i].L, i, a[i].R);
	}

	quitf(_ok, "OK n = %d, k = %d, res = %d", n, k, res);
}
