#include <bits/stdc++.h>
using namespace std;
const int maxN = 300 * 1000 + 5;
const int mod = 1000 * 1000 * 1000;
int a[maxN];
vector<pair<int, int> > c[maxN];
int ps[maxN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++) cin >> a[i], a[i]--, ps[a[i]] = i;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      int x;
      cin >> x;
      x--;
      c[i].push_back(make_pair(ps[x], x));
    }
    sort(c[i].begin(), c[i].end());
  }
  int k;
  cin >> k;
  k--;
  int fl = -1;
  for (int i = 0; i < n; i++)
    if (c[i][0].second == k) {
      fl = i;
      break;
    }
  if (fl == -1) {
    for (int i = 0; i < 3 * n; i++) {
      if (k != i) cout << i + 1 << ' ';
    }
    cout << endl;
    return 0;
  }
  vector<int> ans1, ans2;
  for (int i = 0; i < fl; i++)
    for (int j = 0; j < 3; j++) ans1.push_back(c[i][j].second);
  for (int i = fl + 1; i < n; i++)
    for (int j = 0; j < 3; j++) ans2.push_back(c[i][j].second);
  ans1.push_back(c[fl][1].second);
  ans1.push_back(c[fl][2].second);
  sort(ans1.begin(), ans1.end());
  sort(ans2.begin(), ans2.end());
  while (ans1.size() && ans2.size() && c[fl][1].second != ans1.back() &&
         c[fl][2].second != ans1.back() && ans1.back() > ans2[0])
    ans2.push_back(ans1.back()), ans1.pop_back();
  sort(ans1.begin(), ans1.end());
  sort(ans2.begin(), ans2.end());
  for (auto u : ans1) cout << u + 1 << ' ';
  for (auto u : ans2) cout << u + 1 << ' ';
  cout << endl;
  return 0;
}
