// Arup Guha
// 9/21/2012
// Solution to 2009 MCPC Problem H: Cell Towers

import java.util.*;

public class h {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int t = stdin.nextInt();

		// Process all cases.
		while (t != 0) {

			int n = stdin.nextInt();

			// Read in towers.
			tower[] beacons = new tower[t];
			for (int i=0; i<t; i++) {
				int x = stdin.nextInt();
				int y = stdin.nextInt();
				int pow = stdin.nextInt();
				beacons[i] = new tower(x,y,pow);
			}

			// Read in roads.
			seg[] roads = new seg[n];
			int x1 = stdin.nextInt();
			int y1 = stdin.nextInt();
			int x2 = stdin.nextInt();
			int y2 = stdin.nextInt();
			roads[0] = new seg(new pt(x1, y1), new pt(x2, y2));
			for (int i=1; i<n; i++) {
				x1 = x2;
				y1 = y2;
				x2 = stdin.nextInt();
				y2 = stdin.nextInt();
				roads[i] = new seg(new pt(x1, y1), new pt(x2, y2));
			}

			// Solve and get next case.
			solve(roads, beacons);
			t = stdin.nextInt();
		}
	}

	public static void solve(seg[] roads, tower[] beacons) {

		// For brevity.
		int n = roads.length;
		int t = beacons.length;

		// Set up distance markers.
		double totalD = 0;
		double[] markers = new double[n];
		for (int i=0; i<n; i++) {
			totalD += roads[i].dist;
			markers[i] = totalD;
		}

		// Determine if we need an extra marker.
		boolean extraMarker = false;
		double frac = totalD - (int)totalD;
		if (frac > .5)
			extraMarker = true;

		// Print result for 0.
		int curTower = bestTower(roads[0].start, beacons);
		System.out.print("(0,"+let(curTower)+")");
		double curDistSeg = 0;
		int curSeg = 0;

		// Now, go through other mile markers in order.
		for (int mile=1; mile<=(int)totalD; mile++) {

			int seg = 0;
			while (markers[seg] < mile) seg++;

			// Find best tower.
			double onSeg = mile - (markers[seg] - roads[seg].dist);
			pt curLoc = roads[seg].along(onSeg);
			int newTower = bestTower(curLoc, beacons);

			// Print if we need to update.
			if (newTower != curTower) {
				System.out.print(" ("+mile+","+let(newTower)+")");
				curTower = newTower;
			}
		}

		// Process the last marker.
		if (extraMarker) {
			int newTower = bestTower(roads[n-1].end, beacons);
			if (newTower != curTower) {
				System.out.print(" ("+(int)(totalD+1)+","+let(newTower)+")");
			}
		}
		System.out.println();
	}

	public static char let(int val) {
		return (char)('A' + val);
	}

	// Returns the best tower.
	public static int bestTower(pt loc, tower[] beacons) {

		// Set the default to tower 0.
		int curPow = (int)(beacons[0].power/(Math.pow(loc.dist(beacons[0].loc),2)) + .5 + 1e-10);
		int bestchoice = 0;

		// Just do a brute force search here.
		for (int i=1; i<beacons.length; i++) {
			int newPow = (int)(beacons[i].power/(Math.pow(loc.dist(beacons[i].loc),2)) + .5 + 1e-10);
			if (newPow > curPow) {
				curPow = newPow;
				bestchoice = i;
			}
		}

		// This is our answer.
		return bestchoice;
	}
}

class pt {

	public double x;
	public double y;

	public pt(double myx, double myy) {
		x = myx;
		y = myy;
	}

	public double dist(pt other) {
		return Math.sqrt(Math.pow(this.x-other.x,2) + Math.pow(this.y-other.y,2));
	}

	public String toString() {
		return x +","+y;
	}
}

class tower {

	public pt loc;
	public double power;

	public tower(double x, double y, double pow) {
		loc = new pt(x,y);
		power = pow;
	}
}

class seg {

	public pt start;
	public pt end;
	public double dist;

	public seg(pt a, pt b) {
		start = a;
		end = b;
		dist = start.dist(end);
	}

	// Returns the point that is marker from start to end.
	public pt along(double marker) {
		double ratio = marker/dist;
		double newx = start.x + ratio*(end.x - start.x);
		double newy = start.y + ratio*(end.y - start.y);
		return new pt(newx, newy);
	}

	public double distLeft(double marker) {
		return dist - marker;
	}
	public String toString() {
		return "["+start+":"+end+"]";
	}
}