#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, K, rk[N * 3];
int teams[N][3];
bool cmp(const int &x, const int &y) { return rk[x] < rk[y]; }
void solve() {
  vector<int> pre;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (3); ++j)
      if (teams[i][j] == K) {
        sort(teams[i], teams[i] + 3, cmp);
        if (teams[i][0] == K) {
          pre.push_back(teams[i][1]), pre.push_back(teams[i][2]);
          sort((pre).begin(), (pre).end());
          int p = 0, cnt = 0, flag = 0;
          rk[K] = -1;
          while (cnt < 2) {
            flag ? putchar(' ') : flag = true;
            if (pre[p] == teams[i][1] || pre[p] == teams[i][2]) ++cnt;
            rk[pre[p]] = -1;
            printf("%d", pre[p++]);
          }
          for (int i = (1); i < (3 * n + 1); ++i)
            if (~rk[i]) {
              flag ? putchar(' ') : flag = true;
              printf("%d", i);
            }
        } else {
          bool flag = false;
          for (int i = (1); i < (3 * n + 1); ++i)
            if (i != K) {
              flag ? putchar(' ') : flag = true;
              printf("%d", i);
            }
        }
        return;
      }
    for (int j = (0); j < (3); ++j) pre.push_back(teams[i][j]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i < (3 * n + 1); ++i) {
    int x;
    scanf("%d", &x);
    rk[x] = i;
  }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (3); ++j) scanf("%d", &teams[i][j]);
  scanf("%d", &K);
  solve();
  return 0;
}
