#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

vector<string> ids = {}, old_ids = {};

map<string, int> its, old_its;

vector<pair<int, int>> edges;

vector<vector<int>> edges_of;

int N, old_N;

int id_of(string s) {
  if(its.count(s)) return its[s];
  ids.push_back(s);
  return its[s] = N++;
  }

int rowid;

int old_id_of(string s) {
  if(old_its.count(s)) return old_its[s];
  old_ids.push_back(s);
  return old_its[s] = old_N++;
  }

int main(int argc, char** argv) {
  if(argc != 3) { printf("error: no X or no annealX file\n"); exit(1); }
  int dim = argv[1][0] - '0';

  char buf1[200], buf2[200];
  while(scanf("%s%s", buf1, buf2) == 2) {
    id_of(buf1); id_of(buf2);
    if(rowid) old_id_of(buf1), old_id_of(buf2);
    rowid++;
    }

  ifstream f(argv[2]);
  string s;
  while(getline(f, s)) {
    if(s.find("cellpoints:") != string::npos) break;
    }

  for(int i=0; i<N; i++) {
    getline(f, s);
    int stamp;
    double x, y, z, u;
    if(dim == 2) {
      sscanf(s.c_str(), "%d (%lf,%lf,%lf)", &stamp, &x, &y, &z);
      cout << old_ids[i] << "\n" << z << "\n" << x << "\n" << y << "\n";
      }
    if(dim == 3) {
      sscanf(s.c_str(), "%d (%lf,%lf,%lf,%lf)", &stamp, &x, &y, &z, &u);
      cout << old_ids[i] << "\n" << u << "\n" << x << "\n" << y << "\n" << z << "\n";
      }
    }

  return 0;
  }
