#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[101010 * 3];
int b[101010 * 3];
int _rank[101010 * 3];
int n, m, k;
int main() {
  memset(b, 0, sizeof(b));
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; ++i) {
    scanf("%d", &a[i]);
    _rank[a[i]] = i;
  }
  int len = 0;
  for (int i = 0; i < n; ++i) {
    int p = len;
    for (int j = 0; j < 3; ++j) {
      scanf("%d", &a[len + j]);
      if (_rank[a[len + j]] < _rank[a[p]]) p = len + j;
    }
    for (int j = 0; j < 3; ++j) {
      if (_rank[a[len + j]] == _rank[a[p]])
        b[a[len + j]] = 1;
      else
        b[a[len + j]] = 0;
    }
    len += 3;
  }
  scanf("%d", &k);
  {}
  int t;
  len = 0;
  for (int i = 0; i < n; ++i) {
    if (a[len] == k || a[len + 1] == k || a[len + 2] == k) {
      t = len;
    }
    len += 3;
  }
  for (int i = 0; i < 3 * n; ++i)
    if (a[i] == k) a[i] = -1;
  if (b[k] == 0) {
    sort(a, a + 3 * n);
  } else {
    sort(a, a + t);
    sort(a + t, a + t + 3);
    sort(a + t + 3, a + 3 * n);
    int f1 = 0, f2 = t, r1 = t, r2 = 3 * n, k = 0;
    while (f1 < r1 || f2 < r2) {
      if (f2 >= r2 || f1 < r1 && a[f1] < a[f2]) {
        b[k++] = a[f1++];
      } else
        b[k++] = a[f2++];
    }
    for (int i = 0; i < 3 * n; ++i) a[i] = b[i];
  }
  int flag = 0;
  for (int i = 0; i < 3 * n; ++i) {
    if (a[i] != -1) {
      if (flag++) printf(" ");
      printf("%d", a[i]);
    }
  }
  return 0;
}
