#include <bits/stdc++.h>
const int maxn = 100002;
int n, k;
int triplet[maxn][4];
int result[maxn * 3];
int inTeam[maxn * 3];
bool used[maxn * 3];
int que[maxn * 3];
bool spec1;
int intcmp(const void *p1, const void *p2) { return *(int *)p1 - *(int *)p2; }
int main() {
  using std::cin;
  using std::cout;
  cin >> n;
  int i, j;
  for (i = 1; i <= n * 3; i++) {
    cin >> result[i];
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 3; j++) {
      cin >> triplet[i][j];
      inTeam[triplet[i][j]] = i;
    }
  }
  cin >> k;
  for (i = 1; i <= n * 3; i++) {
    used[i] = false;
  }
  spec1 = false;
  for (i = 1; i <= n * 3; i++) {
    if (used[result[i]]) continue;
    if (result[i] == k) break;
    int team = inTeam[result[i]];
    for (j = 1; j <= 3; j++) {
      int p = triplet[team][j];
      if (p == k) {
        spec1 = true;
        break;
      }
      used[p] = true;
    }
    if (spec1) break;
  }
  if (spec1) {
    bool isHead = true;
    for (i = 1; i <= 3 * n; i++)
      if (i != k) {
        if (isHead) {
          isHead = false;
        } else
          cout << ' ';
        cout << i;
      }
    cout << '\n';
    return 0;
  }
  int m1, m2;
  m1 = 0;
  m2 = 0;
  for (j = 1; j <= 3; j++) {
    i = triplet[inTeam[k]][j];
    if (i != k) {
      if (m1 == 0)
        m1 = i;
      else
        m2 = i;
      used[i] = true;
    }
  }
  if (m1 > m2) {
    int t = m1;
    m1 = m2;
    m2 = t;
  }
  int tail = 0;
  for (i = 1; i <= n * 3; i++) {
    if (i == k) continue;
    if (used[i]) {
      que[++tail] = i;
    }
  }
  for (i = 1; i <= n * 3; i++) {
    if (i == k) continue;
    if (!used[i]) que[++tail] = i;
  }
  for (i = 1; i <= tail; i++)
    if (que[i] == m2) {
      qsort(que + i + 1, tail - i, sizeof(int), intcmp);
      break;
    }
  bool isHead = true;
  for (i = 1; i <= tail; i++) {
    if (isHead)
      isHead = false;
    else
      cout << ' ';
    cout << que[i];
  }
  cout << '\n';
  return 0;
}
