#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    p /= 2;
  }
  return ret;
}
long long power(long long a, long long p) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = (ret * a);
    a = (a * a);
    p /= 2;
  }
  return ret;
}
int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  int i, j, k, tmp;
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int> > a(3 * n + 3);
  int seq[999999];
  vector<int> visit(3 * n + 3, 0);
  for (i = 0; i < 3 * n; i++) {
    cin >> seq[i];
  }
  for (i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a[x].first = y;
    a[x].second = z;
    a[y].first = x;
    a[y].second = z;
    a[z].first = x;
    a[z].second = y;
  }
  vector<int> ans;
  int find;
  cin >> find;
  int fl = 0;
  for (i = 0; i < 3 * n; i++) {
    if (visit[seq[i]] == 1) continue;
    if (find == seq[i]) {
      visit[a[find].first] = 1;
      visit[a[find].second] = 1;
      int nn = max(a[find].first, a[find].second);
      for (i = 1; i <= 3 * n; i++) {
        if (visit[i] == 1) {
          if (i == a[find].first || i == a[find].first)
            cout << i << ' ';
          else if (i > nn)
            visit[i] = 0;
          else
            cout << i << ' ';
        }
      }
      for (i = 1; i <= 3 * n; i++) {
        if (visit[i] == 0 && i != find) cout << i << ' ';
      }
      fl = 1;
      break;
    }
    if (a[seq[i]].first == find || a[seq[i]].second == find) {
      for (i = 1; i <= 3 * n; i++)
        if (i != find) cout << i << ' ';
      fl = 1;
      break;
    }
    visit[seq[i]] = 1;
    visit[a[seq[i]].first] = 1;
    visit[a[seq[i]].second] = 1;
  }
  cout << endl;
  return 0;
}
