#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T, typename TT>
inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {
  return os << t.first << " " << t.second;
}
template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &t) {
  for (auto i : t) os << i << " ";
  return os;
}
template <typename T>
inline istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) is >> t;
  return is;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &is, pair<T1, T2> &t) {
  is >> t.first >> t.second;
  return is;
}
const long long mod = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<int> val(3 * n), vis(3 * n + 1);
  cin >> val;
  vector<int> loc(3 * n + 1);
  vector<vector<long long> > v(n, vector<long long>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> v[i][j];
      loc[v[i][j]] = i;
    }
  }
  int k, j = 0;
  cin >> k;
  vector<int> ans, up;
  for (int i = 0; i < loc[k]; i++) {
    for (auto x : v[i]) vis[x] = 1, up.push_back(x);
  }
  while (vis[val[j]]) j++;
  ;
  if (k != val[j]) {
    for (int i = 1; i <= 3 * n; i++)
      if (i != k) cout << i << " ";
    return;
  }
  for (auto x : v[loc[k]])
    if (x != k) ans.push_back(x);
  for (int i = loc[k] + 1; i < n; i++) {
    for (auto x : v[i]) ans.push_back(x);
  }
  sort(ans.begin(), ans.begin() + 2);
  sort(ans.begin() + 2, ans.end());
  sort(up.begin(), up.end());
  ;
  j = 0;
  for (auto x : ans) {
    while (j < up.size() and up[j] < x) cout << up[j++] << " ";
    cout << x << " ";
  }
  cout << vector<long long>(up.begin() + j, up.end()) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
