// Danny Wasserman
// 7/17/2014
// Solution to SI@UCF Week 2 Contest Problem: Sawyer's Singles

import java.io.IOException;
import java.util.Scanner;

public class singles {
  public static void main(String[] args) throws IOException {

    Scanner in = new Scanner(System.in);
    int cases = in.nextInt();

    // Process each case.
    for (int co = 1; co <= cases; co++) {

      // Where is Sawyer?
      int n = in.nextInt();
      String sawyer = in.next();
      int sx = in.nextInt();
      int sy = in.nextInt();

      String cur = null;
      int d = (int) 1e9;

      // Searching for Danny...
      for (int i = 0; i < n - 1; i++) {

        // Get the potential partner info.
        String name = in.next();
        int x = in.nextInt();
        int y = in.nextInt();
        int d2 = (sx - x) * (sx - x) + (sy - y) * (sy - y);

        // Update if this is the best yet.
        if (d2 < d) {
          d = d2;
          cur = name;
        }

        // Alpha tie...
        if (d2 == d && name.compareTo(cur) < 0) cur = name;
      }

      // And the lucky winner is...
      System.out.println(cur);
    }
  }
}
