#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, c = getchar(), f = 0;
  for (; c > '9' || c < '0'; c = getchar()) f = c == '-';
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  return f ? -x : x;
}
const int N = 100000 + 10;
int n, a[3 * N], b[N][3], k, ans[3 * N];
bool vis[3 * N];
int main() {
  n = read();
  for (int i = 1, _y = 3 * n; i <= _y; i++) a[i] = read();
  for (int i = 1, _y = n; i <= _y; i++)
    for (int j = 0, _y = 2; j <= _y; j++) b[i][j] = read();
  k = read();
  int l = 1;
  for (int i = 1, _y = n; i <= _y; i++) {
    for (; vis[a[l]]; l++)
      ;
    int flag = -1;
    for (int j = 0, _y = 2; j <= _y; j++) {
      vis[b[i][j]] = 1;
      if (b[i][j] == k) flag = j;
    }
    if (flag != -1) {
      if (a[l] == k) {
        int mx = 0;
        for (int j = 0, _y = 2; j <= _y; j++)
          if (j != flag) mx = max(mx, b[i][j]);
        for (int j = 1, _y = mx; j <= _y; j++)
          if (vis[j]) ans[++*ans] = j;
        for (int j = 1, _y = mx; j <= _y; j++)
          if (!vis[j]) ans[++*ans] = j;
        for (int j = mx + 1, _y = 3 * n; j <= _y; j++) ans[++*ans] = j;
      } else
        for (int j = 1, _y = 3 * n; j <= _y; j++) ans[++*ans] = j;
      break;
    }
  }
  for (int i = 1, _y = *ans; i <= _y; i++)
    if (ans[i] != k) printf("%d ", ans[i]);
}
