#include <bits/stdc++.h>
const int N = 100010;
const int inf = 0x3f3f3f3f;
using namespace std;
vector<int> vt[2];
int a[N * 3], b[N][3], n, k;
bool vis[N * 3];
int check(int i) {
  if (b[i][0] == k || b[i][1] == k || b[i][2] == k) return 1;
  return 0;
}
int main() {
  int t = 0;
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &b[i][0], &b[i][1], &b[i][2]);
  scanf("%d", &k);
  int f = 0;
  for (int i = 1, j = 1; i <= n; i++) {
    if (a[j] == k) {
      for (int h = 0; h < 3; h++)
        if (b[i][h] != k) vt[f].push_back(b[i][h]), t = max(t, b[i][h]);
      sort(vt[f].begin(), vt[f].end());
      f++;
    } else if (check(i)) {
      for (int i = 1; i <= 3 * n; i++)
        if (i != k) cout << i << " ";
      cout << endl;
      return 0;
    } else {
      for (int h = 0; h < 3; h++) vt[f].push_back(b[i][h]);
    }
    for (int h = 0; h < 3; h++) vis[b[i][h]] = 1;
    while (vis[a[j]]) j++;
  }
  for (int i = 0; i < ((vt[0]).size()); i++)
    if (vt[0][i] > t)
      vt[1].push_back(vt[0][i]);
    else
      cout << vt[0][i] << " ";
  sort(vt[1].begin(), vt[1].end());
  for (int i = 0; i < ((vt[1]).size()); i++) cout << vt[1][i] << " ";
  cout << endl;
  return 0;
}
