#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, i, var, rank[300010], k, x, y, z, j,
      vis[300010] = {0}, vis1[300010] = {0}, vec[100010][3];
  vector<pair<int, int> > v;
  cin >> n;
  for (i = 1; i <= 3 * n; i++) {
    cin >> var;
    rank[var] = i;
  }
  for (i = 0; i < n; i++) cin >> vec[i][0] >> vec[i][1] >> vec[i][2];
  cin >> k;
  for (i = 0; i < n; i++) {
    x = vec[i][0], y = vec[i][1], z = vec[i][2];
    v.push_back(make_pair(rank[x], x));
    v.push_back(make_pair(rank[y], y));
    v.push_back(make_pair(rank[z], z));
    sort(v.begin(), v.end());
    x = v[0].second, y = v[1].second, z = v[2].second;
    if (k == y || k == z) {
      for (j = 1; j <= 3 * n; j++) {
        if (j == k) continue;
        cout << j << " ";
      }
      cout << "\n";
      return 0;
    } else if (k == x) {
      if (y > z) swap(y, z);
      for (j = 1; j < y; j++) {
        if (vis[j]) {
          vis1[j] = 1;
          cout << j << " ";
        }
      }
      cout << y << " ";
      vis1[y] = 1;
      for (j = y + 1; j < z; j++) {
        if (vis[j]) {
          vis1[j] = 1;
          cout << j << " ";
        }
      }
      cout << z << " ";
      vis1[z] = 1;
      for (j = 1; j <= 3 * n; j++) {
        if (vis1[j] == 0 && j != x) cout << j << " ";
      }
      cout << "\n";
      return 0;
    }
    vis[x] = 1, vis[y] = 1, vis[z] = 1;
    v.clear();
  }
  return 0;
}
