public void solve() throws IOException {
    int n = nextInt();
    nextLine();
    char[][] data = new char[n][];
    for (int i = 0; i < n; i++) {
      data[i] = nextLine().toCharArray();
    }
    nextLine();
    List<String> words = new ArrayList<String>();
    String input = "";
    while ((input = nextLine()) != null && input.length() > 0) {
      words.add(input);
    }
    
    Map<String, Data> map = new HashMap<String, Data>();

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (String word : words) {
          Dir dir = search(data, i, j, word);
          if (dir != null && !map.containsKey(word)) {
            map.put(word, new Data(word, i + 1, j + 1, dir));
          }
        }
      }
    }
    
    for (String word : words) {
      System.out.println(map.get(word).toString());
    }
  }