#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300300;
int n, k, where[MAXN], A[MAXN][3];
bool used[MAXN];
bool bywhere(int v, int w) { return where[v] < where[w]; }
void print(const vector<int> &V) {
  for (int i = (0); i < (int)(((int)V.size())); i++) {
    if (i) printf(" ");
    printf("%d", V[i]);
  }
  puts("");
}
int main() {
  while (scanf("%d", &n) >= 1) {
    memset(used, false, sizeof used);
    for (int i = (0); i < (int)(3 * n); i++) {
      int v;
      scanf("%d", &v);
      where[v] = i;
    }
    for (int i = (0); i < (int)(n); i++) {
      for (int j = (0); j < (int)(3); j++) scanf("%d", &A[i][j]);
      sort(A[i], A[i] + 3, bywhere);
    }
    scanf("%d", &k);
    used[k] = true;
    vector<int> usados;
    bool bad = false;
    for (int i = (0); i < (int)(n); i++) {
      for (int j = (1); j < (int)(3); j++) {
        if (k == A[i][j]) {
          bad = true;
          break;
        }
      }
      for (int j = 3 - 1; j >= 0; j--) {
        used[A[i][j]] = true;
        usados.push_back(A[i][j]);
      }
      if (k == A[i][0]) {
        usados.pop_back();
        vector<int> otros;
        for (int j = (1); j < (int)(3 * n + 1); j++) {
          if (!used[j]) otros.push_back(j);
        }
        vector<int> ans;
        bool stop = false;
        sort(usados.begin(), usados.end());
        for (int z = (0); z < (int)(((int)usados.size())); z++) {
          if (!stop)
            ans.push_back(usados[z]);
          else
            otros.push_back(usados[z]);
          if (usados[z] == max(A[i][1], A[i][2])) stop = true;
        }
        sort(ans.begin(), ans.end());
        sort(otros.begin(), otros.end());
        for (int i = (0); i < (int)(((int)otros.size())); i++)
          ans.push_back(otros[i]);
        print(ans);
        break;
      }
    }
    if (bad) {
      usados.clear();
      for (int j = (1); j < (int)(3 * n + 1); j++)
        if (j != k) usados.push_back(j);
      print(usados);
    }
  }
  return 0;
}
