#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const long long maxn = 3e5 + 10;
const long long inf = 1e18;
long long team[maxn][3];
long long a[maxn];
long long q[maxn], t;
bool mark[maxn];
long long where[maxn];
int32_t main() {
  long long n = in();
  for (long long i = 0; i < 3 * n; i++) a[i] = in(), where[a[i]] = i;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < 3; j++) team[i][j] = in();
  long long who = in();
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 3; j++) {
      if (team[i][j] == who) {
        long long arr[2], cur = 0;
        mark[team[i][j]] = true;
        for (long long j2 = 0; j2 < 3; j2++) {
          if (j2 == j) continue;
          q[t++] = team[i][j2];
          arr[cur++] = team[i][j2];
        }
        if (where[team[i][j]] > min(where[arr[0]], where[arr[1]])) {
          for (long long i = 1; i <= 3 * n; i++) {
            if (mark[i]) continue;
            cout << i << " ";
          }
          return 0;
        }
        sort(q, q + t);
        for (long long i = 0; i < t; i++) {
          if (q[i] > max(arr[0], arr[1])) break;
          cout << q[i] << " ";
          mark[q[i]] = true;
        }
        t = 0;
        for (long long i = 0; i < 3 * n; i++) {
          if (!mark[a[i]]) q[t++] = a[i];
        }
        sort(q, q + t);
        for (long long i = 0; i < t; i++) cout << q[i] << " ";
        cout << endl;
        return 0;
      }
    }
    for (long long j = 0; j < 3; j++) q[t++] = team[i][j];
  }
}
