#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> order(3 * n + 1), ro(3 * n + 1), bo(n, 3 * n + 1);
  for (int i = 1; i <= 3 * n; i++) {
    cin >> order[i];
    ro[order[i]] = i;
  }
  vector<vector<int>> gr(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      int x;
      cin >> x;
      gr[i].push_back(x);
      bo[i] = min(bo[i], ro[x]);
    }
  }
  int k;
  cin >> k;
  int grch = -1;
  for (int i = 0; i < n; i++) {
    for (int x : gr[i]) {
      if (x == k) {
        grch = i;
        break;
      }
    }
  }
  if (bo[grch] != ro[k]) {
    for (int i = 1; i <= 3 * n; i++) {
      if (i == k) continue;
      cout << i << ' ';
    }
    return 0;
  }
  vector<int> used, taken, unused;
  for (int i = 0; i < grch; i++) {
    for (int x : gr[i]) used.push_back(x);
  }
  for (int x : gr[grch]) {
    if (x != k) taken.push_back(x);
  }
  for (int i = grch + 1; i < n; i++) {
    for (int x : gr[i]) unused.push_back(x);
  }
  sort(used.begin(), used.end());
  sort(taken.begin(), taken.end());
  sort(unused.begin(), unused.end());
  queue<int> qu, qt, quu;
  for (int x : used) qu.push(x);
  for (int x : taken) qt.push(x);
  for (int x : unused) quu.push(x);
  while (qu.size() || qt.size() || quu.size()) {
    if (qt.size()) {
      if (qu.size() && qu.front() < qt.front()) {
        cout << qu.front() << ' ';
        qu.pop();
      } else {
        cout << qt.front() << ' ';
        qt.pop();
      }
    } else if (quu.size()) {
      if (qu.size() && qu.front() < quu.front()) {
        cout << qu.front() << ' ';
        qu.pop();
      } else {
        cout << quu.front() << ' ';
        quu.pop();
      }
    } else {
      cout << qu.front() << ' ';
      qu.pop();
    }
  }
  return 0;
}
