#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, mid;
  int target;
  bool simple;
  int team[3 * 100001];
  int seq[3 * 100001];
  bool used[3 * 100001];
  int fmax, ftop, ltop;
  int former[3 * 100001], latter[3 * 100001];
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; i++) scanf("%d", seq + i);
  for (int i = 0; i < n; i++)
    scanf("%d%d%d", team + 3 * i, team + 3 * i + 1, team + 3 * i + 2);
  scanf("%d", &target);
  ftop = 0, ltop = 0;
  mid = (find(team, team + 3 * n, target) - team) / 3;
  for (int i = 0; i < 3; i++)
    if (team[3 * mid + i] != target) former[ftop++] = team[3 * mid + i];
  fmax = max(former[0], former[1]);
  ltop = 3 * (n - mid - 1);
  copy(team + 3 * (mid + 1), team + 3 * n, latter);
  fill(used, used + 3 * n, false);
  for (int i = 0; i < mid; i++) {
    used[team[3 * i]] = true;
    used[team[3 * i + 1]] = true;
    used[team[3 * i + 2]] = true;
  }
  simple = false;
  for (int i = 0; seq[i] != target; i++) {
    if (used[seq[i]] == false) {
      simple = true;
      break;
    }
  }
  if (simple) {
    for (int i = 1; i <= 3 * n; i++)
      if (i != target) printf(i != 1 ? " %d" : "%d", i);
    putchar('\n');
    return 0;
  }
  for (int i = 0; i < mid; i++) {
    for (int j = 0; j < 3; j++) {
      if (team[3 * i + j] < fmax)
        former[ftop++] = team[3 * i + j];
      else
        latter[ltop++] = team[3 * i + j];
    }
  }
  sort(former, former + ftop);
  sort(latter, latter + ltop);
  for (int i = 0; i < ftop; i++) printf(i ? " %d" : "%d", former[i]);
  for (int i = 0; i < ltop; i++) printf(" %d", latter[i]);
  putchar('\n');
  return 0;
}
