#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int rd;
  scanf("%d", &rd);
  return rd;
}
const int N = 3 * 1e5 + 10;
int a[N], n, k, team[N], f[N], s[N];
vector<int> t[N];
bool isCap[N];
int main(int argc, const char* argv[]) {
  n = in();
  for (int i = 1; i <= 3 * n; i++) a[in()] = i;
  for (int i = 1; i <= n; i++) {
    int x = in(), y = in(), z = in();
    team[x] = team[y] = team[z] = i;
    t[i] = {x, y, z};
    if (a[x] < a[y] && a[x] < a[z])
      isCap[x] = 1, f[i] = y, s[i] = z;
    else if (a[y] < a[x] && a[y] < a[z])
      isCap[y] = 1, f[i] = x, s[i] = z;
    else if (a[z] < a[y] && a[z] < a[x])
      isCap[z] = 1, f[i] = x, s[i] = y;
  }
  k = in();
  if (!isCap[k]) {
    for (int i = 1; i <= 3 * n; i++)
      if (i != k) printf("%d ", i);
    return 0;
  }
  vector<int> ans, ans1;
  int tt = team[k];
  if (f[tt] < s[tt]) swap(f[tt], s[tt]);
  for (int i = 1; i < team[k]; i++)
    for (int j = 0; j < t[i].size(); j++)
      if (t[i][j] > f[tt]) ans.push_back(t[i][j]);
  for (int i = tt + 1; i <= n; i++)
    for (int j = 0; j < t[i].size(); j++) ans.push_back(t[i][j]);
  ans1.push_back(s[tt]);
  for (int i = 1; i < team[k]; i++)
    for (int j = 0; j < t[i].size(); j++)
      if (t[i][j] < f[tt]) ans1.push_back(t[i][j]);
  ans1.push_back(f[tt]);
  sort(ans1.begin(), ans1.end());
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans1.size(); i++) printf("%d ", ans1[i]);
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  return 0;
}
