//* Problem  : 
//* Date     : 2009.04.17
//* Author   : alt
//* Tags     : 

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <numeric>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <string>
#include <vector>
#include <cctype>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

//stack
//#pragma comment(linker, "/STACK:16777216")

// to disable Visual C++ secure warnings
#pragma warning(disable : 4996)

///BEGIN CUT HERE
// types
typedef long long int64;
typedef unsigned long long uint64;
typedef pair <int,int> PII;
typedef vector <int> VI;
typedef vector <int64> VI64;
typedef vector <string> VS;
typedef vector <vector<string> > VVS;
typedef vector <vector<int> > VVI;
typedef vector <pair<int,int> > VPII;
typedef vector <vector<pair<int,int> > > VVPII;
typedef map<int, int > MII;
typedef map<string, int > MSI;
typedef queue<int > QI;
typedef queue<PII > QPII;
//loops
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FORR(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define FORE(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FORER(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define FORSZ(i, a) FOR(i, SZ(a))
#define FORSZR(i, a) FORR(i, SZ(a))
#define FORO(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define FOROR(i, x) for (typeof((x).end()) i = (x).end(); i != (x).begin(); i--)
#define REP(n) for (int _foo = (int)(n) - 1; _foo >= 0; _foo--)
#define REP2(n) for (int _foo2 = (int)(n) - 1; _foo2 >= 0; _foo2--)

#define VAR(a, b) typeof(b) a=(b)
#define FOREACH(it, c) for(VAR(it,(c).begin()); it!=(c).end(); it++)
//sorting & c
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define SORT(a) sort(ALL(a))
#define RSORT(a) sort(RALL(a))
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define REVERSE(a) reverse(ALL(a))
//filling
#define FLA(a,val) memset(a, val, sizeof(a))
#define FLO(o,val) memset(&o, val, sizeof(o))
#define CLA(a) FLA(a, 0)
#define CLO(a) FLO(a, 0)
//misc
#define _x first
#define _y second
#define MP make_pair
#define PB push_back
#define SZ(a) (int)a.size()
#define POP(a) a.top(), a.pop()
#define FRONT(a) a.front(), a.pop()
//const
const int INF = 1000000000;
const int64 INFL = 1000000000000000000LL;
const double PI = acos(-1.0);
const double EPS = 1E-9;

const int dx8[] = {-1, 1, 0, 0, -1, -1,  1, 1};
const int dy8[] = {0, 0, -1, 1, -1,   1, -1, 1};

//some math
template <typename T> inline T gcd(T a, T b)				{ return b ? gcd(b, a % b) : a; }
template <typename T> inline T gcd2(T a, T b)				{ while (a && b) (a > b) ? a %= b : b %= a; return a + b;}
template <typename T> inline T lcm(T a, T b)				{ return a / gcd(a, b) * b; }
template <typename T> inline T abs(T a)					{ return a < 0 ? -a : a; }
template <typename T> inline T sqr(T a)					{ return a * a; }
template <typename T> inline double hypot(T a, T b)		{ return sqrt(1.0 * a * a + b * b);}
//template <typename T> inline double hypot(T a, T b, T ñ)	{ return sqrt(1.0 * a * a + b * b + ñ * ñ);}
template <typename T> inline T hypot2(T a, T b)			{ return a * a + b * b;}
//template <typename T> inline T hypot2(T a, T b, T c)		{ return a * a + b * b + c * c;}
template <typename T> inline void chMin(T& a, T b) { if (b < a) a = b; }
template <typename T> inline void chMax(T& a, T b) { if (b > a) a = b; }

//assertions
#ifdef _DEBUG
#define ASSERT(f) if (!(f)) printf("%s\n", "ASSERTION FAILED!");
#define ASSERTS(f, s) if (!(f)) printf("%s [%s]\n", "ASSERTION FAILED!", s);
#else
#define ASSERT(f) f
#define ASSERTS(f, s) f
#endif

int cmp_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int cmp_double(const void *a, const void *b){double t = *(double*)a - *(double*)b;return (fabs(t) < EPS) ? 0 : t > 0 ? 1 : -1;}
int cmp_int64(const void *a, const void *b){int64 t = *(int64*)a - *(int64*)b; return !t ? 0 : t > 0 ? 1 : -1;}

//input
inline void ri(int &tt){ASSERTS(scanf("%d", &tt) == 1, "ReadInt failed");}
inline int ri(){int tt; ASSERTS(scanf("%d", &tt) == 1, "ReadInt failed"); return tt;}
inline void ri64(int64 &tt){ASSERTS(scanf("%lld", &tt) == 1, "ReadInt64 failed");}
inline int64 ri64(){int64 tt; ASSERTS(scanf("%lld", &tt) == 1, "ReadInt64 failed"); return tt;}
inline void rd(double &tt){ASSERTS(scanf("%lf", &tt) == 1, "ReadDouble failed"); }
inline double rd(){double tt; ASSERTS(scanf("%lf", &tt) == 1, "ReadDouble failed"); return tt;}
inline void rs(char *s){ASSERTS(scanf("%s", s) == 1, "ReadChar* failed");}
//output
inline void pvi(int *a, int n){FOR(i, n) printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');}
inline void pvi(VI a){FORSZ(i,a) printf("%d%c", a[i], i == a.size() - 1 ? '\n' : ' ');}
inline void pi(int n){printf("%d\n", n);}
inline void pi64(int64 n){printf("%lld\n", n);}

inline void _pi64(int64 n)
{
	if (n < 0) {putchar('-'); n = -n;}
	if (!n) {putchar('0'); return;}
	char stack[30]; int istack = 0;
	while (n)
	{
		stack[istack++] = (n % 10) + '0'; n /= 10;
	}
	while (istack > 0)
		putchar(stack[--istack]);
}
const int dx4[] = {-1, 1, 0, 0};
const int dy4[] = {0, 0, -1, 1};
///END CUT HERE

struct point{
	int x, y;
};

struct segment{
	point p1, p2;
};

struct figure{
	int n;
	point a[32];
	char ch;
}a[32];

bool cmp(figure a, figure b)
{
	return a.ch < b.ch;
}

int n, res;

void solve()
{
}

void read_int(int &r)
{
	r = 0;
	char c = 0;
	int sign = 0;
	while (!((c >= '0' && c <= '9') || (c == '-'))) c = getchar();
	if (c == '-')
	{
		sign = 1; c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		r = 10 * r + c - '0'; c = getchar();
	}
	if (sign)
		r = -r;
	r *= 2;
}

point read_point()
{
	point res;
	read_int(res.x);
	read_int(res.y);
	return res;
}

void do_it(point p, point po, point &r)
{
	int dx2 = po.x - p.x;
	int dy2 = po.y - p.y;
	r.x = po.x + dy2;
	r.y = po.y - dx2;
}

int read_figure(figure &r)
{
	char c = 0; 
	while (!(c == '-' || c == '.' || (c >= 'A' && c <= 'Z')))
		c = getchar();
	if (c == '-') return 0;
	if (c == '.') return -1;
	r.ch = c;
	char s[100]; rs(s);
	if (s[0] == 'l')
	{
		r.n = 2;
		r.a[0] = read_point();
		r.a[1] = read_point();
	}
	else if (s[0] == 'r')
	{
		r.n = 4;
		r.a[0] = read_point();
		r.a[1] = read_point();
		r.a[2] = read_point();
		r.a[3].x = r.a[0].x + r.a[2].x - r.a[1].x;
		r.a[3].y = r.a[0].y + r.a[2].y - r.a[1].y;
	}
	else if (s[0] == 't')
	{
		r.n = 3;
		r.a[0] = read_point();
		r.a[1] = read_point();
		r.a[2] = read_point();
	}
	else if (s[0] == 'p')
	{
		r.n = ri();
		FOR(i, r.n)
			r.a[i] = read_point();

	}
	else if (s[0] == 's')	
	{
		r.n = 4;
		r.a[0] = read_point();
		r.a[2] = read_point();
		point po;
		po.x = (r.a[0].x + r.a[2].x)/2;
		po.y = (r.a[0].y + r.a[2].y)/2;
		do_it(r.a[0], po, r.a[1]);
		do_it(r.a[2], po, r.a[3]);
#ifdef _DEBUG
		printf("%d %d\n", r.a[1].x, r.a[1].y);
		printf("%d %d\n", r.a[3].x, r.a[3].y);
#endif
		//r.a[1].x = r.a[3].x = 2;
		//r.a[1].y = 1;
		//r.a[3].y = 3;
	}
	return 1;
}

int triangle_square2(point &a, point &b, point &c)
{
	return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
}

int in_ex(int a, int b, int c, int d)
{
	return max(c, d) >= min(a, b) && min(c, d) <= max(a, b);
}

int intersecting_segments(segment &a, segment &b)
{
	int64 sq11 = triangle_square2(a.p1, a.p2, b.p1);
	int64 sq12 = triangle_square2(a.p1, a.p2, b.p2);
	int64 sq21 = triangle_square2(b.p1, b.p2, a.p1);
	int64 sq22 = triangle_square2(b.p1, b.p2, a.p2);
	if (sq11 == 0 && sq22 == 0 && sq12 == 0 && sq21 == 0)
		return in_ex(a.p1.x, a.p2.x, b.p1.x, b.p2.x) && in_ex(a.p1.y, a.p2.y, b.p1.y, b.p2.y);

	return (sq11 * sq12 <= 0) && (sq21 * sq22 <= 0);
}

int inters(figure &a, figure &b)
{
	FOR(i1, a.n)
	{
		segment s1;
		s1.p1 = a.a[i1];
		s1.p2 = a.a[(i1 + 1)%a.n];
		FOR(i2, b.n)
		{
			segment s2;
			s2.p1 = b.a[i2];
			s2.p2 = b.a[(i2 + 1)%b.n];
			if (intersecting_segments(s1, s2)) 
				return 1;
		}
	}
	return 0;
}

int main()
{
#ifdef _DEBUG
	freopen("1064", "r", stdin);
	//freopen("1064o", "w", stdout);
#endif
	while (1)
	{
		n = 0;
		int k;
		while ((k = read_figure(a[n])) > 0) n++;
		if (k < 0) break;
		sort(a, a + n, cmp);
		char r[32]; int rc;
		FOR(i,n)
		{
			rc = 0;
			FOR(j, n) if (i - j)
				if (inters(a[i], a[j]))
					r[rc++] = a[j].ch;
			if (!rc)
			{
				printf("%c has no intersections\n", a[i].ch);
			}
			else if (rc == 1)
			{
				printf("%c intersects with %c\n", a[i].ch, r[0]);
			}
			else if (rc == 2)
			{
				printf("%c intersects with %c and %c\n", a[i].ch, r[0], r[1]);
			}
			else
			{
				printf("%c intersects with ", a[i].ch);
				for (int t = 0; t < rc - 1; t++)
					printf("%c, ", r[t]);
				printf("and %c\n", r[rc-1]);
			}
		}
		puts("");
	}
}

