#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
void solve() {
  int n;
  cin >> n;
  vector<int> place(3 * n + 1);
  for (int i = 0; i < 3 * n; ++i) {
    int a;
    cin >> a;
    place[a] = i;
  }
  const int FREE = 0, TAKEN = 1, OUTPUT = 2;
  vector<int> taken(3 * n + 1, FREE);
  vector<int> order(3 * n);
  for (int i = 0; i < 3 * n; ++i) cin >> order[i];
  int k;
  cin >> k;
  for (int i = 0; i < 3 * n; i += 3) {
    set<int> team(&order[i], &order[i + 3]);
    if (team.find(k) == team.end()) {
      for (int p : team) taken[p] = TAKEN;
      continue;
    }
    team.erase(k);
    int p1 = *team.begin(), p2 = *team.rbegin();
    if (place[k] > place[p1] || place[k] > place[p2]) {
      for (int p = 1; p <= 3 * n; ++p)
        if (p != k) {
          cout << p << " ";
        }
      return;
    }
    auto f = [&](int next) {
      for (int p = 1; p < next; ++p)
        if (p != k && taken[p] == TAKEN) {
          cout << p << " ";
          taken[p] = OUTPUT;
        }
      cout << next << " ";
      taken[next] = OUTPUT;
    };
    f(p1);
    f(p2);
    for (int p = 1; p <= 3 * n; ++p)
      if (p != k && taken[p] != OUTPUT) cout << p << " ";
    return;
  }
  throw std::logic_error("Unreachable");
}
