#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
  if (fabs(d) < eps) return 0;
  return d > eps ? 1 : -1;
}
int a[111111][4], p[333333], o[333333];
int n;
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < 3 * n; i++) {
    scanf("%d", p + i);
    o[p[i]] = i;
  }
  for (i = 0; i < n; i++) {
    int mi = 1111111;
    for (j = 0; j < 3; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int r;
  scanf("%d", &r);
  int t = -1;
  int mx = -1;
  for (i = 0; i < n; i++) {
    int mi = 1111111;
    for (j = 0; j < 3; j++) {
      mi = min(mi, o[a[i][j]]);
    }
    if (mi == o[r]) {
      t = i;
      for (j = 0; j < 3; j++) {
        if (a[i][j] == r) continue;
        mx = max(mx, a[i][j]);
      }
    }
  }
  if (t == -1 || t == n - 1) {
    for (i = 1; i <= 3 * n; i++)
      if (i != r) printf("%d ", i);
    puts("");
    return 0;
  }
  vector<int> ls, rs;
  for (i = 0; i <= t; i++) {
    for (j = 0; j < 3; j++) {
      if (a[i][j] != r) {
        if (a[i][j] <= mx)
          ls.push_back(a[i][j]);
        else
          rs.push_back(a[i][j]);
      }
    }
  }
  sort(ls.begin(), ls.end());
  for (i = 0; i < (int)((ls).size()); i++) printf("%d ", ls[i]);
  ls.clear();
  for (i = t + 1; i < n; i++) {
    for (j = 0; j < 3; j++) {
      if (a[i][j] != r) rs.push_back(a[i][j]);
    }
  }
  sort(rs.begin(), rs.end());
  for (i = 0; i < (int)((rs).size()); i++) printf("%d ", rs[i]);
  puts("");
  return 0;
}
