#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, p, q;
int A[300001], T[300001][4];
vector<int> V, V2, V3;
vector<int> merge(vector<int> L, vector<int> R) {
  int n = L.size(), m = R.size(), i = 0, j = 0, k;
  vector<int> V;
  L.push_back(1000000000);
  R.push_back(1000000000);
  for (k = 0; k < n + m; k++)
    if (L[i] < R[j])
      V.push_back(L[i++]);
    else
      V.push_back(R[j++]);
  return V;
}
int main() {
  scanf("%d", &n);
  for (i = 0; i < 3 * n; i++) scanf("%d", &A[i]);
  for (i = 0; i < n; i++)
    for (j = 0; j < 3; j++) scanf("%d", &T[i][j]);
  scanf("%d", &k);
  for (i = 0; i < n && T[i][0] != k && T[i][1] != k && T[i][2] != k; i++)
    ;
  for (j = 0; A[j] != T[i][0] && A[j] != T[i][1] && A[j] != T[i][2]; j++)
    ;
  if (A[j] != k) {
    for (i = 1; i <= 3 * n; i++)
      if (i != k) printf("%d ", i);
    return 0;
  }
  for (p = 0; p < i; p++)
    for (q = 0; q < 3; q++) V.push_back(T[p][q]);
  for (p = 0; p < 3; p++)
    if (T[i][p] != k) V2.push_back(T[i][p]);
  for (p = i + 1; p < n; p++)
    for (q = 0; q < 3; q++) V3.push_back(T[p][q]);
  sort(V.begin(), V.end());
  sort(V2.begin(), V2.end());
  sort(V3.begin(), V3.end());
  for (i = 0; i < V3.size(); i++) V2.push_back(V3[i]);
  V = merge(V, V2);
  for (i = 0; i < V.size(); i++) printf("%d ", V[i]);
  return 0;
}
