#include <bits/stdc++.h>
using namespace std;
int team[100001][3], p[300001], n, k;
bool vis[300001];
void print(int Mx) {
  priority_queue<int, vector<int>, greater<int> > q;
  for (int i = 1; i <= 3 * n; i++)
    if (vis[i]) q.push(i);
  while (!q.empty()) {
    int c = q.top();
    q.pop();
    cout << c << ' ';
    if (c == Mx) break;
  }
  for (int i = 1; i <= 3 * n; i++)
    if (!vis[i] && i != k) q.push(i);
  while (!q.empty()) {
    int c = q.top();
    q.pop();
    printf("%d ", c);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++) scanf("%d", p), p[p[0]] = i;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) scanf("%d", &team[i][j]);
  scanf("%d", &k);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++)
      if (team[i][j] == k) {
        int x = team[i][(j + 1) % 3], y = team[i][(j + 2) % 3];
        vis[x] = vis[y] = 1;
        if (p[x] > p[k] && p[y] > p[k])
          print(max(x, y));
        else
          for (int i = 1; i <= 3 * n; i++)
            if (i != k) printf("%d ", i);
      } else
        vis[team[i][j]] = 1;
  return 0;
}
