#include <bits/stdc++.h>
using namespace std;
int n;
int pos[310000];
bool occ[310000];
int A[310000];
int B[310000];
int C[310000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; i++) {
    int x;
    scanf("%d", &x);
    x--;
    pos[x] = i;
  }
  for (int i = 0; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x--;
    y--;
    z--;
    if (pos[x] < pos[y] && pos[x] < pos[z]) {
      A[i] = x;
      B[i] = y;
      C[i] = z;
    }
    if (pos[y] < pos[x] && pos[y] < pos[z]) {
      A[i] = y;
      B[i] = x;
      C[i] = z;
    }
    if (pos[z] < pos[x] && pos[z] < pos[y]) {
      A[i] = z;
      B[i] = x;
      C[i] = y;
    }
  }
  int k;
  scanf("%d", &k);
  k--;
  bool isleader = false;
  vector<int> L1;
  vector<int> L2;
  for (int i = 0; i < n; i++) {
    if (A[i] == k) {
      isleader = true;
      vector<int> L;
      for (int j = i + 1; j < n; j++) {
        L.push_back(A[j]);
        L.push_back(B[j]);
        L.push_back(C[j]);
      }
      sort(L.begin(), L.end());
      L1.push_back(min(B[i], C[i]));
      L1.push_back(max(B[i], C[i]));
      for (int j = 0; j < L.size(); j++) L1.push_back(L[j]);
      for (int j = 0; j < i; j++) {
        L2.push_back(A[j]);
        L2.push_back(B[j]);
        L2.push_back(C[j]);
      }
      sort(L2.begin(), L2.end());
      break;
    }
  }
  if (isleader) {
    int p1 = 0;
    int p2 = 0;
    vector<int> answer;
    while (p1 < L1.size() || p2 < L2.size()) {
      if (p1 == L1.size()) {
        answer.push_back(L2[p2]);
        p2++;
        continue;
      }
      if (p2 == L2.size()) {
        answer.push_back(L1[p1]);
        p1++;
        continue;
      }
      if (L1[p1] < L2[p2]) {
        answer.push_back(L1[p1]);
        p1++;
      } else {
        answer.push_back(L2[p2]);
        p2++;
      }
    }
    for (int i = 0; i < answer.size(); i++) printf("%d ", answer[i] + 1);
    printf("\n");
  } else {
    for (int i = 0; i < 3 * n; i++)
      if (i != k) printf("%d ", i + 1);
    printf("\n");
  }
}
