#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmax(T &a, T b) {
  return (a > b) ? a : a = b;
}
namespace Poor {
const int MaxiN = 100005;
int N, K;
int List[MaxiN * 3];
int Team[MaxiN][3];
bool Known[MaxiN * 3], Use[MaxiN * 3];
void Run() {
  scanf("%d", &N);
  for (int i = 1; i <= N * 3; ++i) scanf("%d", List + i);
  for (int i = 1; i <= N; ++i)
    for (int j = 0; j < 3; ++j) scanf("%d", &Team[i][j]);
  scanf("%d", &K);
  fill(Known + 1, Known + N * 3 + 1, 0);
  int k = 1;
  for (int i = 1; i <= N * 3; ++i)
    if (!Known[List[i]]) {
      for (int j = 0; j < 3; ++j)
        if (Team[k][j] == K) {
          if (K == List[i]) {
            fill(Use + 1, Use + N * 3 + 1, 0);
            int Big = 0;
            for (int g = 0; g < 3; ++g)
              if (g != j) {
                Use[Team[k][g]] = 1;
                checkmax(Big, Team[k][g]);
              }
            for (int g = 1; g <= Big; ++g)
              if (Known[g]) Use[g] = 1;
            int Cnt = 0;
            for (int g = 1; g <= N * 3; ++g)
              if (g != K && Use[g]) {
                ++Cnt;
                printf("%d%c", g, (Cnt == N * 3 - 1) ? '\n' : ' ');
              }
            for (int g = 1; g <= N * 3; ++g)
              if (g != K && !Use[g]) {
                ++Cnt;
                printf("%d%c", g, (Cnt == N * 3 - 1) ? '\n' : ' ');
              }
          } else {
            int Cnt = 0;
            for (int g = 1; g <= N * 3; ++g)
              if (g != K) {
                ++Cnt;
                printf("%d%c", g, (Cnt == N * 3 - 1) ? '\n' : ' ');
              }
          }
        }
      for (int j = 0; j < 3; ++j) Known[Team[k][j]] = 1;
      ++k;
    }
}
}  // namespace Poor
int main() {
  Poor::Run();
  return 0;
}
