#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
map<int, int> od;
map<int, int> te;
vector<int> pr, af;
int a[3][maxn];
int main() {
  cin >> n;
  for (int i = 0; i < 3 * n; ++i) {
    int x;
    cin >> x;
    od[x] = i + 1;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[0][i] >> a[1][i] >> a[2][i];
    te[a[0][i]] = te[a[1][i]] = te[a[2][i]] = i + 1;
  }
  int ro;
  cin >> ro;
  int tt = te[ro] - 1;
  if (od[ro] <= od[a[0][tt]] && od[ro] <= od[a[1][tt]] &&
      od[ro] <= od[a[2][tt]]) {
    int mx = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 3; ++j)
        if (a[j][i] != ro) {
          if (i <= tt) {
            if (i == tt) mx = max(mx, a[j][i]);
            pr.push_back(a[j][i]);
          } else {
            af.push_back(a[j][i]);
          }
        }
    }
    sort(pr.begin(), pr.end());
    for (int i = 0; i < pr.size(); ++i) {
      if (pr[i] <= mx)
        cout << pr[i] << ' ';
      else
        af.push_back(pr[i]);
    }
    sort(af.begin(), af.end());
    for (int i = 0; i < af.size(); ++i) cout << af[i] << ' ';
    cout << endl;
  } else {
    for (int i = 1; i <= 3 * n; ++i) {
      if (i != ro) cout << i << ' ';
    }
    cout << endl;
  }
  return 0;
}
