#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int n, m, data[maxn];
bool vis[maxn], used[maxn];
int mate[maxn][2];
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++) scanf("%d", &data[i]);
  for (int i = 1; i <= n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    mate[a][0] = b, mate[a][1] = c;
    mate[b][0] = a, mate[b][1] = c;
    mate[c][0] = a, mate[c][1] = b;
  }
  scanf("%d", &m);
}
void solve() {
  for (int i = 1; i <= 3 * n; i++) {
    int p = data[i];
    if (p == m && vis[p]) {
      for (int i = 1; i <= 3 * n; i++)
        if (i != m) printf("%d ", i);
      printf("\n");
      return;
    }
    if (vis[p]) continue;
    if (p != m)
      vis[p] = vis[mate[p][0]] = vis[mate[p][1]] = true;
    else {
      int cnt = 0;
      for (int i = 1; i <= 3 * n; i++)
        if (i != p)
          if (vis[i] || i == mate[p][0] || i == mate[p][1]) {
            used[i] = true;
            printf("%d ", i);
            if ((i == mate[p][0] || i == mate[p][1]) && ++cnt == 2) break;
          }
      for (int i = 1; i <= 3 * n; i++)
        if (i != p && !used[i]) printf("%d ", i);
      printf("\n");
      return;
    }
  }
}
int main() {
  input();
  solve();
  return 0;
}
