#include "testlib.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;

int const MIN_N =  0;
int const MAX_N =  3;
int const MIN_C =  2;
int const MAX_C = 10;
int const MIN_A = -3;
int const MAX_A = +3;
int const FULL_CIRCLE = 360;

double const EPS = 1E-9;

struct laser
{
	int x, y, a;
};

struct point
{
	double x, y;
	point (void) {}
	point (double nx, double ny): x (nx), y (ny) {}
};

struct coord
{
	int x, y;
	coord (void) {x = -1; y = -1;}
	coord (int nx, int ny): x (nx), y (ny) {}
	bool operator == (coord const & other) const
	{
		return (x == other.x) && (y == other.y);
	}
	bool operator != (coord const & other) const
	{
		return !(*this == other);
	}
};

coord const NA = coord ();

double lim1;
double lim2;

double vp (point a, point b, point c)
{
	return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}

double sp (point a, point b, point c)
{
	return (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y);
}

bool possible (point a, point b, point c, point u, point v)
{
	if ((abs (a.x - u.x) < EPS) && (abs (a.y - u.y) < EPS))
	{
		assert (false);
	}
	if ((abs (a.x - v.x) < EPS) && (abs (a.y - v.y) < EPS))
	{
		return false;
	}
	if ((sp (a, b, u) <= +EPS) && (sp (a, b, v) <= +EPS) &&
	    (sp (a, c, u) <= +EPS) && (sp (a, c, v) <= +EPS))
	{
		return true;
	}
	double x = vp (a, b, u);
	if (abs (x) < EPS)
	{
		return true;
	}
	double y = vp (a, c, v);
	lim1 = min (lim1, abs (y));
	lim2 = min (lim2, x * y);
	return (abs (y) > EPS) && (x * y > EPS);
}

string const IMPOSSIBLE = "None";

void check (int n, laser * p, string res, TResult wrong)
{
	if (res == IMPOSSIBLE)
	{
		return;
	}

	int t = (int) res.size ();
	for (int i = 0; i < n; i++)
	{
		int da = p[i].a * t;
		da %= FULL_CIRCLE;
		if (da != 0)
		{
			quitf (wrong, "Laser %i is facing %d degrees "
			              "at the end, must be zero", i + 1, da);
		}
	}

	point q [n];
	for (int i = 0; i < n; i++)
	{
		q[i] = point (p[i].x, p[i].y);
	}

	point r [t + 1] [n];
	for (int s = 0; s <= t; s++)
	{
		for (int i = 0; i < n; i++)
		{
			double angle = 0.25 + p[i].a * s * 1.0 / FULL_CIRCLE;
			angle *= 2.0 * M_PI;
			r[s][i] = point (p[i].x + cos (angle),
			                 p[i].y + sin (angle));
		}
	}

	int x = 0;
	int y = 0;
	for (int s = 0; s < t; s++)
	{
		int dz = res[s] - '1';
		int dx = dz % 3 - 1;
		int dy = dz / 3 - 1;
		point u = point (x, y);
		int nx = x + dx;
		int ny = y + dy;
		point v = point (nx, ny);
		
		for (int i = 0; i < n; i++)
		{
			if ((nx == p[i].x) && (ny == p[i].y))
			{
				quitf (wrong, "At step %d: moved onto source "
				              "%d (%d, %d)", s + 1, i + 1,
				              p[i].x, p[i].y);
			}
		}
		for (int i = 0; i < n; i++)
		{
			if (!possible (q[i], r[s][i], r[s + 1][i], u, v))
			{
				quitf (wrong, "At step %d: crossed beam %d "
				              "moving (%d, %d) -> (%d, %d); "
				              "min-epsilon: %.1le, %.1le",
				              s + 1, i + 1, x, y, nx, ny,
				              lim1, lim2);
			}
		}

		x = nx;
		y = ny;
	}

	if (x != 0 || y != 0)
	{
		quitf (wrong, "At (%d, %d) at the end, must be origin",
                       x, y);
	}
}

int main (int argc, char * argv [])
{
	setName ("checker for problem revolving-lasers");
	registerTestlibCmd (argc, argv);
	
	int n = inf.readInt (MIN_N, MAX_N);
	laser p [n];
	for (int i = 0; i < n; i++)
	{
		p[i].x = inf.readInt (MIN_C, MAX_C);
		p[i].y = inf.readInt (MIN_C, MAX_C);
		p[i].a = inf.readInt (MIN_A, MAX_A);
	}

	string ja = ans.readWord ("None|[1-9]{1,10000}");
	string pa = ouf.readWord ("None|[1-9]{1,10000}");

	lim1 = 1.0 / EPS;
	lim2 = 1.0 / EPS;
	check (n, p, ja, _fail);
	lim1 = 1.0 / EPS;
	lim2 = 1.0 / EPS;
	check (n, p, pa, _wa);

	if (pa == IMPOSSIBLE && ja == IMPOSSIBLE)
	{
		quitf (_ok, "impossible");
	}

	if (pa != IMPOSSIBLE && ja == IMPOSSIBLE)
	{
		quitf (_fail, "jury: impossible, participant: possible");
	}

	if (pa == IMPOSSIBLE && ja != IMPOSSIBLE)
	{
		quitf (_wa, "jury: possible, participant: impossible");
	}

	if (pa != IMPOSSIBLE && ja != IMPOSSIBLE)
	{
		quitf (_ok, "actions: jury %d, participant %d; "
		            "min-epsilon: %.1le, %.1le",
		            (int) ja.size (), (int) pa.size (), lim1, lim2);
	}

	assert (false);
	return _fail;
}
