#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000,100000000")
using namespace std;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long double pi = 2 * acos(0.0);
const long double e = 2.71828;
long long a[300005];
long long ra[300005];
long long h[300005];
vector<long long> v;
struct sett {
  int x, y, z;
} t[100005];
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= 3 * n; i++) cin >> a[i], ra[i] = a[i];
  for (int i = 1; i <= 3 * n; i++) a[ra[i]] = i;
  for (int i = 1; i <= n; i++) {
    cin >> t[i].x >> t[i].y >> t[i].z;
    if (a[t[i].x] > a[t[i].y] && a[t[i].x] > a[t[i].z]) {
      if (a[t[i].y] < a[t[i].z]) swap(t[i].y, t[i].z);
    } else if (a[t[i].y] > a[t[i].x] && a[t[i].y] > a[t[i].z]) {
      swap(t[i].x, t[i].y);
      if (a[t[i].y] < a[t[i].z]) swap(t[i].y, t[i].z);
    } else if (a[t[i].z] > a[t[i].y] && a[t[i].z] > a[t[i].x]) {
      swap(t[i].x, t[i].z);
      if (a[t[i].y] < a[t[i].z]) swap(t[i].y, t[i].z);
    }
  }
  int k;
  cin >> k;
  int ok = 0;
  for (int i = 1; i <= n; i++)
    if (t[i].z == k) ok = i;
  if (!ok) {
    for (int i = 1; i <= 3 * n; i++)
      if (i != k) cout << i << " ";
    cout << endl;
  } else {
    for (int i = 1; i <= ok; i++) {
      if (t[i].x <= max(t[ok].x, t[ok].y)) v.push_back(t[i].x), h[t[i].x] = 1;
      if (t[i].y <= max(t[ok].x, t[ok].y)) v.push_back(t[i].y), h[t[i].y] = 1;
      if (t[i].z <= max(t[ok].x, t[ok].y) || i == ok)
        v.push_back(t[i].z), h[t[i].z] = 1;
    }
    v.pop_back();
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
    for (int i = 1; i <= 3 * n; i++)
      if (!h[i] && i != k) cout << i << " ";
  }
  return 0;
}
