#include <bits/stdc++.h>
using namespace std;
int n, me, a[300001];
set<int> b[100001];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++) {
    scanf("%d", &me);
    a[me] = i;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 3; j++) {
      scanf("%d", &me);
      b[i].insert(me);
    }
  scanf("%d", &me);
  set<int> u;
  for (int i = 1; i <= n; i++) {
    u.insert(b[i].begin(), b[i].end());
    if (!b[i].count(me)) continue;
    b[i].erase(me);
    u.erase(me);
    if (a[me] > a[*b[i].begin()] || a[me] > a[*b[i].rbegin()]) continue;
    set<int> other;
    for (auto x : u)
      if (x <= *b[i].rbegin())
        printf("%d ", x);
      else
        other.insert(x);
    u = other;
  }
  for (auto x : u) printf("%d ", x);
}
