#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
const int N = 100005;
int n, i, j, poz[3 * N], tab[3 * N], m, mat[3 * N], k, wyb[3 * N], bat[N][3],
    ind;
vector<int> l1, l2;
int main() {
  scanf("%d", &n);
  for (i = 0; i < 3 * n; i++) {
    scanf("%d", &tab[i]);
    poz[tab[i]] = i;
  }
  for (i = 0; i < n; i++) {
    m = INF;
    for (j = 0; j < 3; j++) {
      scanf("%d", &bat[i][j]);
      if (poz[bat[i][j]] < m) {
        ind = bat[i][j];
        m = poz[ind];
      }
      mat[bat[i][j]] = i;
    }
    wyb[ind] = i + 1;
  }
  scanf("%d", &k);
  if (wyb[k] == 0) {
    for (i = 1; i <= 3 * n; i++)
      if (i != k) printf("%d ", i);
    return 0;
  }
  m = 0;
  for (i = 0; i < 3; i++)
    if (bat[mat[k]][i] != k) m = max(m, bat[mat[k]][i]);
  for (i = 0; i < wyb[k]; i++)
    for (j = 0; j < 3; j++)
      if (bat[i][j] != k && bat[i][j] <= m) l1.push_back(bat[i][j]);
  for (i = 0; i < n; i++)
    for (j = 0; j < 3; j++)
      if ((bat[i][j] != k) && (i >= wyb[k] || bat[i][j] > m))
        l2.push_back(bat[i][j]);
  sort(l1.begin(), l1.end());
  sort(l2.begin(), l2.end());
  for (i = 0; i < l1.size(); i++) printf("%d ", l1[i]);
  for (i = 0; i < l2.size(); i++) printf("%d ", l2[i]);
  return 0;
}
