#include <bits/stdc++.h>
using namespace std;
int a[100010][3];
int b[300010];
int c[300010];
int mp[300010];
int main() {
  int n;
  cin >> n;
  int i, j;
  for (i = 0; i < 3 * n; i++) {
    int tmp;
    cin >> tmp;
    mp[tmp] = i;
  }
  int pos;
  for (i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
  int k;
  cin >> k;
  int now = mp[k];
  for (i = 0; i < n; i++) {
    for (j = 0; j < 3; j++) {
      if (a[i][j] == k) {
        pos = i;
        break;
      }
    }
    if (j < 3) break;
  }
  for (i = 0; i < pos; i++)
    for (j = 0; j < 3; j++)
      if (mp[a[i][j]] < mp[k]) now--;
  if (now) {
    for (i = 1; i <= 3 * n; i++) {
      if (i != k) {
        cout << i;
        if (i < 3 * n) cout << " ";
      }
    }
    cout << endl;
    return 0;
  }
  int r = 0;
  for (i = 0; i < 3; i++)
    if (a[pos][i] != k) b[r++] = a[pos][i];
  int mn = max(b[0], b[1]);
  int m = 0;
  for (i = 0; i < pos; i++)
    for (j = 0; j < 3; j++) {
      if (a[i][j] < mn)
        b[r++] = a[i][j];
      else
        c[m++] = a[i][j];
    }
  for (i = pos + 1; i < n; i++)
    for (j = 0; j < 3; j++) c[m++] = a[i][j];
  sort(b, b + r);
  sort(c, c + m);
  for (i = 0; i < r; i++) cout << b[i] << " ";
  for (i = 0; i < m; i++) cout << c[i] << " ";
  cout << endl;
  return 0;
}
