public void solve() throws IOException {
    int tests = nextInt();
    for (int t = 0; t < tests; t++) {
      ArrayList<String> buildings = new ArrayList<String>();
      ArrayList<int[]> coordinates = new ArrayList<int[]>();
      ArrayList<Distance> distances = new ArrayList<Distance>();

      int updates = nextInt();

      for (int x = 0; x < updates; x++) {
        int type = nextInt();
        String name = nextToken();
        if (type == 1) {
          int[] coor = new int[2];
          coor[0] = nextInt();
          coor[1] = nextInt();
          int index = buildings.size();

          for (int y = 0; y < coordinates.size(); y++) {
            distances.add(new Distance(getDist(coor, coordinates.get(y)), index, y));
          }
          Collections.sort(distances);

          buildings.add(name);
          coordinates.add(coor);
        } else {
          int index = buildings.indexOf(name);
          buildings.remove(index);
          coordinates.remove(index);

          for (int y = 0; y < distances.size(); y++) {
            if (distances.get(y).index1 == index || distances.get(y).index2 == index) {
              distances.remove(y);
              y--;
            }
          }
        }

        if (buildings.size() <= 1)
          System.out.println(buildings.size() - 1);
        else {
          System.out.println(distances.get(0).distance);
        }
      }
    }
  }