
#ifdef BURUNDUK
#	include "my_testlib.h"
#else
#	include "testlib.h"
#endif

#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()

struct Car {
	int a, b, i, sa, sb;
};
int n;
vector<Car> c;

void readInput(InStream &in) {
	n = in.readInt();
	c.resize(n);
	forn(i, n) {
		c[i].a = in.readInt();
		c[i].b = in.readInt();
		c[i].i = i;
	}
}

int checkOutput(InStream &out) {
	int ans = out.readInt();
	vector<Car> car = c;
	forn(i, n) {
		car[i].sa = out.readInt();
		car[i].sb = out.readInt();
		auto good = [&](int l, int len) { return 0 <= l && l <= ans && l + len <= ans; };
		if (!good(car[i].sa, car[i].a)) out.quitf(_wa, "car #%d - trying to wash outside period [0..%d]", i+1, ans);
		if (!good(car[i].sb, car[i].b)) out.quitf(_wa, "car #%d - trying to clean outside period [0..%d]", i+1, ans);
		if (max(car[i].sa, car[i].sb) < min(car[i].sa + car[i].a, car[i].sb + car[i].b))
		 	out.quitf(_wa, "car %d - trying to wash and clean at same time", i+1);
	}
	sort(all(car), [](Car x, Car y){ return x.sa < y.sa; });
	forn(i, n-1)
		if (car[i].sa + car[i].a > car[i + 1].sa)
			out.quitf(_wa, "cars %d and %d are washed at the same time", car[i].i + 1, car[i+1].i + 1);
	sort(all(car), [](Car x, Car y){ return x.sb < y.sb; });
	forn(i, n-1)
		if (car[i].sb + car[i].b > car[i + 1].sb)
			out.quitf(_wa, "cars %d and %d are cleaned at the same time", car[i].i + 1, car[i+1].i + 1);
	return ans;
}

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

	readInput(inf);

	int ja = checkOutput(ans);
	int ca = checkOutput(ouf);

	if (ca != ja)
		quitf(ca  > ja ? _wa : _fail, "Contestant says %d, jury say %d", ca, ja);
	quitf(_ok, "OK (n = %d, answer = %d)", n, ja);
}
