#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(T a, int n) {
  for (int i = 0; i < n; ++i) cout << a[i] << ' ';
  cout << endl;
}
template <class T>
void show(T a, int r, int l) {
  for (int i = 0; i < r; ++i) show(a[i], l);
  cout << endl;
}
const int N = 110000;
const int M = 5000;
const int oo = 10000 * 10000 * 10;
int n;
bool out[N * 3] = {false};
int a[N * 3];
int tmm[N][3];
int m;
int tag1, tag2;
int id[N * 3];
inline bool in(int i) {
  if (i == tag1 || i == tag2) return true;
  return false;
}
void solve() {
  int i, j, k;
  int d = 0;
  for (i = 0; i < n; ++i) {
    while (out[a[d]]) ++d;
    for (j = 0; j < 3; ++j)
      if (tmm[i][j] == a[d]) break;
    for (k = 0; k < 3; ++k) out[tmm[i][k]] = true;
    if (tmm[i][j] == m) {
      swap(tmm[i][j], tmm[i][0]);
      tag1 = tmm[i][1];
      tag2 = tmm[i][2];
      vector<int> v1;
      vector<int> v2;
      for (i = 1; i <= 3 * n; ++i) {
        if (i == m) continue;
        if (out[i])
          v1.push_back(i);
        else
          v2.push_back(i);
      }
      sort(v1.begin(), v1.end());
      sort(v2.begin(), v2.end());
      i = 0, j = 0;
      int out_n = 0;
      for (i = 0; i < v1.size(); ++i) {
        if (in(v1[i])) ++out_n;
        printf("%d ", v1[i]);
        if (out_n == 2) {
          ++i;
          break;
        }
      }
      while (i < v1.size() && j < v2.size()) {
        if (v1[i] < v2[j])
          printf("%d ", v1[i++]);
        else
          printf("%d ", v2[j++]);
      }
      while (i < v1.size()) printf("%d ", v1[i++]);
      while (j < v2.size()) printf("%d ", v2[j++]);
      return;
    }
  }
  for (k = 1; k <= 3 * n; ++k) {
    if (k == m) continue;
    printf("%d ", k);
  }
  putchar(10);
}
int main() {
  int i, j, cas = 0;
  scanf("%d", &n);
  for (i = 0; i < n * 3; ++i) scanf("%d", &a[i]);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < 3; ++j) scanf("%d", &tmm[i][j]);
  }
  scanf("%d", &m);
  solve();
  return 0;
}
