Problem: A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication devices and can exchange observational data with ones nearby. They also have large capacity memory units, on which they record data observed by themselves and those received from others.

Figure 1 illustrates the current positions of three robots A, B, and C and the geographic coverage of their wireless devices. Each circle represents the wireless coverage of a robot, with its center representing the position of the robot. In this figure, two robots A and B are in the positions where A can transmit data to B, and vice versa. In contrast, C cannot communicate with A or B, since it is too remote from them. Still, however, once B moves towards C as in Figure 2, B and C can start communicating with each other. In this manner, B can relay observational data from A to C. Figure 3 shows another example, in which data propagate among several robots instantaneously.

<image>
---
Figure 1: The initial configuration of three robots
<image>
---
Figure 2: Mobile relaying
<image>
---
Figure 3: Instantaneous relaying among multiple robots

As you may notice from these examples, if a team of robots move properly, observational data quickly spread over a large number of them. Your mission is to write a program that simulates how information spreads among robots. Suppose that, regardless of data size, the time necessary for communication is negligible.



Input

The input consists of multiple datasets, each in the following format.

> N T R
>  nickname and travel route of the first robot
>  nickname and travel route of the second robot
>  ...
>  nickname and travel route of the N-th robot
>

The first line contains three integers N, T, and R that are the number of robots, the length of the simulation period, and the maximum distance wireless signals can reach, respectively, and satisfy that 1 <=N <= 100, 1 <= T <= 1000, and 1 <= R <= 10.

The nickname and travel route of each robot are given in the following format.

> nickname
>  t0 x0 y0
>  t1 vx1 vy1
>  t2 vx2 vy2
>  ...
>  tk vxk vyk
>

Nickname is a character string of length between one and eight that only contains lowercase letters. No two robots in a dataset may have the same nickname. Each of the lines following nickname contains three integers, satisfying the following conditions.

> 0 = t0 < t1 < ... < tk = T
>  -10 <= vx1, vy1, ..., vxk, vyk<= 10
>

A robot moves around on a two dimensional plane. (x0, y0) is the location of the robot at time 0. From time ti-1 to ti (0 < i <= k), the velocities in the x and y directions are vxi and vyi, respectively. Therefore, the travel route of a robot is piecewise linear. Note that it may self-overlap or self-intersect.

You may assume that each dataset satisfies the following conditions.

* The distance between any two robots at time 0 is not exactly R.
* The x- and y-coordinates of each robot are always between -500 and 500, inclusive.
* Once any robot approaches within R + 10-6 of any other, the distance between them will become smaller than R - 10-6 while maintaining the velocities.
* Once any robot moves away up to R - 10-6 of any other, the distance between them will become larger than R + 10-6 while maintaining the velocities.
* If any pair of robots mutually enter the wireless area of the opposite ones at time t and any pair, which may share one or two members with the aforementioned pair, mutually leave the wireless area of the opposite ones at time t', the difference between t and t' is no smaller than 10-6 time unit, that is, |t - t' | >= 10-6.


A dataset may include two or more robots that share the same location at the same time. However, you should still consider that they can move with the designated velocities.

The end of the input is indicated by a line containing three zeros.

Output

For each dataset in the input, your program should print the nickname of each robot that have got until time T the observational data originally acquired by the first robot at time 0. Each nickname should be written in a separate line in dictionary order without any superfluous characters such as leading or trailing spaces.

Example

Input

3 5 10
red
0 0 0
5 0 0
green
0 5 5
5 6 1
blue
0 40 5
5 0 0
3 10 5
atom
0 47 32
5 -10 -7
10 1 0
pluto
0 0 0
7 0 0
10 3 3
gesicht
0 25 7
5 -7 -2
10 -1 10
4 100 7
impulse
0 -500 0
100 10 1
freedom
0 -491 0
100 9 2
destiny
0 -472 0
100 7 4
strike
0 -482 0
100 8 3
0 0 0


Output

blue
green
red
atom
gesicht
pluto
freedom
impulse
strike

Solution (in CPP):

Solution:
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<cassert>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

#define sq(x)      ((x)*(x))
#define sqsum(x,y) (sq(x)+sq(y))

using namespace std;

struct path{ int n,t[1001],x[1001],y[1001]; };

struct event{ // ロボットの接触イベント
	double t;
	int u,v,io; // ロボット u と v が触れた(io=0)か離れた(io=1)か
	bool operator<(const event &e)const{ return t<e.t; }
};

vector<double> solve_quadratic_equation(double a,double b,double c){
	if(a==0) return vector<double>(0); // a==0 は 2 つのロボットが相対的にみて動いてないということだから, このときイベントは起こらない

	if(b*b-4*a*c<0) return vector<double>(0);
	vector<double> res(2);
	res[0]=(-b-sqrt(b*b-4*a*c))/(2*a);
	res[1]=(-b+sqrt(b*b-4*a*c))/(2*a);
	return res;
}

// パス P の時刻 t での位置を求める
void calc_point(const path &P,int t,int &x,int &y){
	x=P.x[0];
	y=P.y[0];
	rep(i,P.n-1){
		if(t<=P.t[i+1]){
			x+=(t-P.t[i])*P.x[i+1];
			y+=(t-P.t[i])*P.y[i+1];
			return;
		}
		x+=(P.t[i+1]-P.t[i])*P.x[i+1];
		y+=(P.t[i+1]-P.t[i])*P.y[i+1];
	}
	assert(0);
}

int R;

void calc_touch_points(const path &P,const path &Q,int u,int v,vector<event> &E){
	vector<int> t;
	t.insert(t.end(),P.t,P.t+P.n);
	t.insert(t.end(),Q.t,Q.t+Q.n);
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());

	rep(k,t.size()-1){
		int x1,y1,x2,y2,x3,y3,x4,y4;
		calc_point(P,t[ k ],x1,y1);
		calc_point(P,t[k+1],x2,y2);
		calc_point(Q,t[ k ],x3,y3);
		calc_point(Q,t[k+1],x4,y4);

		int a=sqsum(x2-x1+x3-x4,y2-y1+y3-y4);
		int b=2*(x2-x1+x3-x4)*(x1-x3)+2*(y2-y1+y3-y4)*(y1-y3);
		int c=sqsum(x1-x3,y1-y3)-R*R;
		vector<double> sol=solve_quadratic_equation(a,b,c);
		if(sol.size()==2){
			if(0<=sol[0] && sol[0]<=1) E.push_back((event){t[k]+sol[0]*(t[k+1]-t[k]),u,v,0});
			if(0<=sol[1] && sol[1]<=1) E.push_back((event){t[k]+sol[1]*(t[k+1]-t[k]),u,v,1});
		}
	}
}

int main(){
	for(int n,T;scanf("%d%d%d",&n,&T,&R),n;){
		char s[100][9];
		path P[100];
		rep(i,n){
			scanf("%s",s[i]);
			int m=0,t,x,y;
			while(1){
				scanf("%d%d%d",&t,&x,&y);
				P[i].t[m]=t;
				P[i].x[m]=x;
				P[i].y[m]=y;
				m++;
				if(t==T) break;
			}
			P[i].n=m;
		}

		vector<event> E;
		rep(j,n) rep(i,j) calc_touch_points(P[i],P[j],i,j,E);

		sort(E.begin(),E.end());

		bool ans[100]={true};
		bool adj[100][100]={}; // ロボット i と j が通信できるかどうか
		// 初期状態を計算
		rep(i,n) rep(j,n) if(i!=j && sqsum(P[i].x[0]-P[j].x[0],P[i].y[0]-P[j].y[0])<=R*R) {
			adj[i][j]=adj[j][i]=true;
		}
		rep(_,n) rep(i,n) rep(j,n) if(adj[i][j]) {
			ans[i]|=ans[j];
			ans[j]|=ans[i];
		}
		// シミュレーション
		queue<int> Q;
		rep(i,E.size()){
			event e=E[i];
			int u=e.u,v=e.v;
			if(e.io==0){
				adj[u][v]=adj[v][u]=true;

				if(ans[u]==ans[v]) continue;
				// ans[u]!=ans[v] のとき
				// BFS でロボット 0 の情報を広める
				int tar=(ans[u]?v:u);
				ans[tar]=true;
				assert(Q.empty());
				Q.push(tar);
				while(!Q.empty()){
					int w=Q.front(); Q.pop();
					rep(x,n) if(adj[w][x] && !ans[x]) { ans[x]=true; Q.push(x); }
				}
			}
			else{
				adj[u][v]=adj[v][u]=false;
			}
		}

		vector<string> s_ans;
		rep(i,n) if(ans[i]) s_ans.push_back(s[i]);
		sort(s_ans.begin(),s_ans.end());
		rep(i,s_ans.size()) puts(s_ans[i].c_str());
	}

	return 0;
}