#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30, N = 100002;
int ax[] = {0, 1, -1, 0, 0};
int ay[] = {0, 0, 0, -1, 1};
int us[3 * N], x[N], y[N], z[N];
vector<int> v;
int main() {
  int n, i, j, k, tm, b;
  cin >> n;
  for (i = 1; i <= 3 * n; i++) {
    cin >> b;
    us[b] = i;
  }
  for (i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i];
  cin >> k;
  for (i = 1; i <= n; i++)
    if (k == x[i] || k == z[i] || y[i] == k) {
      tm = i;
      break;
    }
  int mn;
  if ((k == x[tm] && us[k] < us[y[tm]] && us[k] < us[z[tm]]) ||
      (k == y[tm] && us[k] < us[x[tm]] && us[k] < us[z[tm]]) ||
      (k == z[tm] && us[k] < us[x[tm]] && us[k] < us[y[tm]])) {
    if (x[tm] == k) mn = max(y[tm], z[tm]);
    if (y[tm] == k) mn = max(x[tm], z[tm]);
    if (z[tm] == k) mn = max(y[tm], x[tm]);
    if (x[tm] != k) v.push_back(x[tm]);
    if (y[tm] != k) v.push_back(y[tm]);
    if (z[tm] != k) v.push_back(z[tm]);
    for (i = 1; i < tm; i++) {
      if (x[i] < mn) v.push_back(x[i]);
      if (y[i] < mn) v.push_back(y[i]);
      if (z[i] < mn) v.push_back(z[i]);
    }
    sort(v.begin(), v.end());
    for (i = 0; i < v.size(); i++) cout << v[i] << ' ';
    v.clear();
    for (i = 1; i < tm; i++) {
      if (x[i] > mn) v.push_back(x[i]);
      if (y[i] > mn) v.push_back(y[i]);
      if (z[i] > mn) v.push_back(z[i]);
    }
    for (i = tm + 1; i <= n; i++) {
      v.push_back(x[i]);
      v.push_back(y[i]);
      v.push_back(z[i]);
    }
    sort(v.begin(), v.end());
    for (i = 0; i < v.size(); i++) cout << v[i] << ' ';
  } else {
    for (i = 1; i <= 3 * n; i++)
      if (i != k) cout << i << ' ';
  }
  return 0;
}
