#include <bits/stdc++.h>
using namespace std;
const int L = 3e5 + 10;
int order[L];
int team[L / 3][3];
int revt[L];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++) {
    int a;
    scanf("%d", &a);
    order[a] = i;
  }
  for (int i = 0; i < n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    team[i][0] = a;
    team[i][1] = b;
    team[i][2] = c;
    revt[a] = i;
    revt[b] = i;
    revt[c] = i;
  }
  int k;
  scanf("%d", &k);
  int t = revt[k];
  bool cap = true;
  for (int i = 0; i < 3; i++) {
    if (order[k] > order[team[t][i]]) {
      cap = false;
    }
  }
  auto sp = "";
  if (!cap) {
    for (int i = 1; i <= 3 * n; i++) {
      if (i == k) continue;
      printf("%s%d", sp, i);
      sp = " ";
    }
  } else {
    sort(team[t], team[t] + 3);
    int v = team[t][2];
    if (v == k) {
      v = team[t][1];
    }
    vector<int> a, b;
    for (int i = 1; i <= 3 * n; i++) {
      if (i == k) continue;
      if (revt[i] <= t && i <= v) {
        a.push_back(i);
      } else {
        b.push_back(i);
      }
    }
    for (auto i : a) {
      printf("%s%d", sp, i);
      sp = " ";
    }
    for (auto i : b) {
      printf("%s%d", sp, i);
      sp = " ";
    }
  }
  puts("");
  return 0;
}
