#include <bits/stdc++.h>
using namespace std;
int n;
int id[101101 * 3];
bool chosen[101101 * 3];
int leader[101101 * 3];
int v[101101 * 3], lv;
int pre[101101 * 3], lpre;
int suf[101101 * 3], lsuf;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++) {
    scanf("%d", &id[i]);
  }
  int it = 1;
  lv = 0;
  for (int i = 1; i <= n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    v[lv++] = a;
    v[lv++] = b;
    v[lv++] = c;
    while (chosen[id[it]]) it++;
    leader[id[it]] = i;
    chosen[a] = chosen[b] = chosen[c] = true;
  }
  int k;
  scanf("%d", &k);
  if (!leader[k] || leader[k] == n) {
    for (int i = 1; i <= 3 * n; i++)
      if (i != k)
        printf("%d%c", i,
               (k != 3 * n && i < 3 * n || k == 3 * n && i < 3 * n - 1) ? ' '
                                                                        : '\n');
  } else {
    int x = leader[k] - 1;
    int lim = 0;
    lpre = lsuf = 0;
    for (int i = x * 3; i < x * 3 + 3; i++)
      if (v[i] != k) lim = max(lim, v[i]);
    for (int i = 0; i < x * 3; i++)
      if (v[i] < lim)
        pre[lpre++] = v[i];
      else
        suf[lsuf++] = v[i];
    for (int i = x * 3; i < x * 3 + 3; i++)
      if (v[i] != k) pre[lpre++] = v[i];
    for (int i = x * 3 + 3; i < n * 3; i++) suf[lsuf++] = v[i];
    sort(pre, pre + lpre);
    sort(suf, suf + lsuf);
    for (int i = 0; i < lpre; i++) printf("%d ", pre[i]);
    for (int i = 0; i < lsuf; i++)
      printf("%d%c", suf[i], i < lsuf - 1 ? ' ' : '\n');
  }
  return 0;
}
