#include <bits/stdc++.h>
using namespace std;
struct gr {
  int u, v, w;
};
bool check[300001];
int n, k, d[300001];
gr a[100001];
int main() {
  cin >> n;
  for (int i = 1; i <= 3 * n; i++) {
    int k;
    scanf("%d", &k);
    d[i] = k;
  }
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &a[i].u, &a[i].v, &a[i].w);
  cin >> k;
  for (int i = 1; i <= n; i++) {
    check[a[i].u] = true;
    check[a[i].v] = true;
    check[a[i].w] = true;
    if (a[i].u == k || a[i].v == k || a[i].w == k) {
      int c;
      for (int j = 1; j <= 3 * n; j++)
        if (a[i].u == d[j] || a[i].v == d[j] || a[i].w == d[j]) {
          c = d[j];
          break;
        }
      if (c != k) {
        for (int j = 1; j <= 3 * n; j++)
          if (j != k) cout << j << " ";
        return 0;
      }
      if (a[i].v == k) swap(a[i].u, a[i].v);
      if (a[i].w == k) swap(a[i].w, a[i].u);
      for (int j = 1; j <= max(a[i].v, a[i].w); j++)
        if (check[j] && j != k) printf("%d ", j);
      for (int j = 1; j <= max(a[i].v, a[i].w); j++)
        if (!check[j]) printf("%d ", j);
      for (int j = max(a[i].v, a[i].w) + 1; j <= 3 * n; j++)
        if (j != k) cout << j << " ";
    }
  }
}
