#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
long int n, k;
vector<long int> a;
struct team {
  long int a, b, c;
  team(long int _a, long int _b, long int _c) {
    a = _a;
    b = _b;
    c = _c;
  }
};
long int power(long int x) {
  for (long int i = a.size() - 1; i >= 0; i--)
    if (a[i] == x) return -i;
}
int main() {
  cin >> n;
  a.resize(3 * n);
  for (long int i = 0; i < 3 * n; i++) cin >> a[i];
  vector<team> t;
  for (long int i = 0; i < n; i++) {
    long int a, b, c;
    cin >> a >> b >> c;
    t.push_back(team(a, b, c));
  }
  cin >> k;
  long int cur;
  for (long int i = 0; i < n; i++)
    if (t[i].a == k || t[i].b == k || t[i].c == k) {
      cur = i;
      break;
    }
  vector<long int> ans;
  if (t[cur].a == k)
    if (power(t[cur].a) > max(power(t[cur].b), power(t[cur].c))) {
      ans.push_back(t[cur].b);
      ans.push_back(t[cur].c);
    }
  if (t[cur].b == k)
    if (power(t[cur].b) > max(power(t[cur].a), power(t[cur].c))) {
      ans.push_back(t[cur].a);
      ans.push_back(t[cur].c);
    }
  if (t[cur].c == k)
    if (power(t[cur].c) > max(power(t[cur].b), power(t[cur].a))) {
      ans.push_back(t[cur].b);
      ans.push_back(t[cur].a);
    }
  if (ans.size() == 0) {
    for (long int i = 1; i <= 3 * n; i++)
      if (i != k) cout << i << " ";
    return 0;
  }
  long int mx = max(ans[0], ans[1]);
  vector<long int> ans1;
  for (long int i = 0; i < cur; i++) {
    if (t[i].a < mx)
      ans.push_back(t[i].a);
    else
      ans1.push_back(t[i].a);
    if (t[i].b < mx)
      ans.push_back(t[i].b);
    else
      ans1.push_back(t[i].b);
    if (t[i].c < mx)
      ans.push_back(t[i].c);
    else
      ans1.push_back(t[i].c);
  }
  sort(ans.begin(), ans.end());
  for (long int i = cur + 1; i < n; i++) {
    ans1.push_back(t[i].a);
    ans1.push_back(t[i].b);
    ans1.push_back(t[i].c);
  }
  sort(ans1.begin(), ans1.end());
  for (long int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  for (long int i = 0; i < ans1.size(); i++) cout << ans1[i] << " ";
  return 0;
}
