#include <bits/stdc++.h>
using namespace std;
void no() {
  cout << "-1\n";
  exit(0);
}
void yes() { cout << "YES\n"; }
int nxt() {
  int x;
  cin >> x;
  return x;
}
void solve() {
  int n = nxt();
  int M = 3 * n;
  vector<int> a(M + 1), taken(M + 1);
  for (int i = (int)1; i < (int)M + 1; i++) {
    cin >> a[i];
  }
  vector<vector<int> > teams(n, vector<int>(3));
  for (int i = (int)0; i < (int)n; i++) {
    for (int j = (int)0; j < (int)3; j++) cin >> teams[i][j];
  }
  int k = nxt();
  int id = 0;
  for (int i = (int)1; i < (int)M + 1; i++)
    if (a[i] == k) id = i;
  vector<int> others;
  for (int i = (int)0; i < (int)n; i++) {
    bool found = 0;
    for (int j = (int)0; j < (int)3; j++) {
      if (teams[i][j] == k) {
        found = 1;
      }
    }
    if (not found)
      for (int j = (int)0; j < (int)3; j++) taken[teams[i][j]] = 1;
    else {
      for (int j = (int)0; j < (int)3; j++)
        if (teams[i][j] != k) others.push_back(teams[i][j]);
      break;
    }
  }
  vector<int> ans;
  bool onebefore = 0;
  for (int i = (int)1; i < (int)id; i++) {
    if (not taken[a[i]]) onebefore = 1;
  }
  42;
  if (onebefore) {
    for (int i = (int)1; i < (int)M + 1; i++)
      if (i != k) ans.push_back(i);
  } else {
    sort(others.begin(), others.end());
    vector<bool> alive(M + 1, 1);
    alive[k] = 0;
    set<int> tempans(others.begin(), others.end());
    int maxi = *max_element(others.begin(), others.end());
    for (int i = (int)1; i < (int)M + 1; i++) {
      if (i != k) {
        if (taken[i] && i < maxi) tempans.insert(i);
      }
    }
    for (int x : tempans) {
      ans.push_back(x);
      alive[x] = 0;
    }
    for (int i = (int)1; i < (int)M + 1; i++)
      if (alive[i]) ans.push_back(i);
    42;
  }
  assert(((long long)ans.size()) == M - 1);
  for (int x : ans) cout << x << " ";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int tc = 1; tc <= t; tc++) {
    solve();
  }
}
