#include <bits/stdc++.h>
using namespace std;
void boostIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const int maxn = 1e5 + 5;
const int inf = 1e9 + 7;
int n, k;
int w[maxn * 3];
int a[maxn * 3];
int main() {
  boostIO();
  cin >> n;
  for (int i = 1; i <= 3 * n; ++i) {
    int tmp;
    cin >> tmp;
    w[tmp] = i;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      int tmp;
      cin >> tmp;
      a[tmp] = i;
    }
  }
  cin >> k;
  bool flag = false;
  int mx = -inf;
  int mn = inf;
  for (int i = 1; i <= 3 * n; ++i)
    if (i != k && a[i] == a[k]) {
      if (w[i] < w[k]) {
        flag = true;
        break;
      } else {
        mx = max(mx, i);
        mn = min(mn, i);
      }
    }
  if (flag) {
    for (int i = 1; i <= 3 * n; ++i)
      if (i != k) cout << i << ' ';
  } else {
    vector<int> beg, end;
    for (int i = 1; i <= 3 * n; ++i)
      if (i != k) {
        if (a[i] == a[k])
          beg.push_back(i);
        else if (a[i] < a[k] && i < mx)
          beg.push_back(i);
        else
          end.push_back(i);
      }
    sort(beg.begin(), beg.end());
    sort(end.begin(), end.end());
    for (auto& el : beg) cout << el << ' ';
    for (auto& el : end) cout << el << ' ';
  }
  return 0;
}
