#include <bits/stdc++.h>
using namespace std;
const int N = 300048;
int r[N], n, sh = 0, s[N];
bool L[N];
vector<int> x, y, z;
void ssv(vector<int> t) {
  sort(t.begin(), t.end());
  int sz = t.size();
  for (int i = 0; i < sz; ++i) printf("%d%c", t[i], ++sh == n ? '\n' : ' ');
}
int main(void) {
  int t;
  scanf("%d", &n);
  n *= 3;
  for (int i = 0; i < n; ++i) scanf("%d", &t), r[t] = i, L[i] = 0;
  L[n] = L[n + 1] = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &s[i]);
    if (i % 3 == 2) {
      int c = s[i];
      if (r[s[i - 1]] < r[c]) c = s[i - 1];
      if (r[s[i - 2]] < r[c]) c = s[i - 2];
      L[c] = 1;
    }
  }
  scanf("%d", &t);
  if (!L[t])
    for (int i = 1; i < n + 1; ++i) {
      if (i == t) continue;
      printf("%d%c", i, ++sh == n ? '\n' : ' ', i);
    }
  else {
    int a[3], b;
    for (b = 0; s[b] != t; ++b)
      ;
    b = (b / 3) * 3;
    for (int i = 0; i < 3; ++i) a[i] = s[b + i] == t ? N : s[b + i];
    sort(a, a + 3);
    for (int i = 0; i < b; ++i) {
      if (s[i] < a[0])
        x.push_back(s[i]);
      else if (s[i] < a[1])
        y.push_back(s[i]);
      else
        z.push_back(s[i]);
    }
    x.push_back(a[0]);
    y.push_back(a[1]);
    for (int i = b + 3; i < n; ++i) z.push_back(s[i]);
    ssv(x);
    ssv(y);
    ssv(z);
  }
  return 0;
}
