#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
const int inf = (int)1e9;
const int MAX_N = 400 * 1000;
vector<int> v, w, s;
int n;
int a[MAX_N];
int mark[MAX_N];
int arr[MAX_N][3];
int main() {
  cin >> n;
  for (int i = 0; i < 3 * n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) cin >> arr[i][j];
  int k;
  cin >> k;
  for (int i = 0; i < n; i++) {
    bool sw = 0;
    for (int j = 0; j < 3; j++) {
      if (arr[i][j] == k)
        sw = 1;
      else
        mark[arr[i][j]] = 1;
    }
    if (sw) {
      for (int j = 0; j < 3; j++) mark[arr[i][j]] = 0;
      break;
    }
  }
  bool isok = 0;
  for (int i = 0; i < 3 * n; i++) {
    if (mark[a[i]] == 0) {
      isok = (a[i] == k);
      break;
    }
  }
  if (isok == 0) {
    for (int i = 1; i <= 3 * n; i++) {
      if (i != k) printf("%d ", i);
    }
    cout << endl;
    return 0;
  }
  int sw = 0, sw2 = 0, idx = -1;
  for (int i = 0; i < n; i++) {
    if (sw) sw2 = 1;
    for (int j = 0; j < 3; j++) {
      if (arr[i][j] == k)
        sw = 1, idx = i;
      else {
        if (sw2)
          w.push_back(arr[i][j]);
        else
          v.push_back(arr[i][j]);
      }
    }
  }
  int maxi = -1;
  for (int j = 0; j < 3; j++) {
    if (arr[idx][j] != k) maxi = max(arr[idx][j], maxi);
  }
  sort(v.begin(), v.end());
  sort(w.begin(), w.end());
  s.assign(v.begin(), v.end());
  s.insert(s.end(), w.begin(), w.end());
  for (int i = 0; i < ((int)s.size()); i++) {
    if (s[i] == maxi) {
      sort(s.begin() + i + 1, s.end());
      break;
    }
  }
  for (int i = 0; i < ((int)s.size()); i++) printf("%d ", s[i]);
  cout << endl;
  return 0;
}
