#include <bits/stdc++.h>
using namespace std;
bool was[300005];
int arr[300005];
int arr2[300005];
void fin(int n, int k) {
  for (int i = 1; i <= 3 * n; i++) {
    if (i != k) {
      printf("%d ", i);
    }
  }
}
int main() {
  int n, k;
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 0; i < 3 * n; i++) {
    scanf("%d", &arr2[i]);
  }
  scanf("%d", &k);
  int cur = 0, tec = 0;
  while (1) {
    while (was[arr[cur]]) {
      cur++;
    }
    for (int i = 0; i < 3; i++) {
      was[arr2[i + tec]] = true;
    }
    if (was[k]) {
      if (arr[cur] == k) {
        sort(arr2 + tec, arr2 + tec + 3);
        if (arr2[tec + 2] == k) {
          swap(arr2[tec + 2], arr2[tec + 1]);
        }
        for (int i = 1; i <= arr2[tec + 2]; i++) {
          if (was[i] && i != k) {
            printf("%d ", i);
          }
        }
        for (int i = arr2[tec + 2] + 1; i <= 3 * n; i++) {
          if (i != k) was[i] = false;
        }
        for (int i = 1; i <= 3 * n; i++) {
          if (!was[i]) {
            printf("%d ", i);
          }
        }
        return 0;
      } else {
        fin(n, k);
        return 0;
      }
    }
    tec += 3;
  }
  return 0;
}
