#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000LL;
const double EPS = 1e-9;
const long long mod = 1000000007ll;
const int maxn = 500500;
int ra[maxn];
map<int, int> rra;
int ord[3][maxn];
int pr[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i < (int)(n * 3 + 1); ++i)
    scanf("%d", &ra[i]), rra[ra[i]] = i;
  for (int i = 0; i < (int)(n); ++i)
    scanf("%d%d", &ord[0][i], &ord[1][i]), scanf("%d", &ord[2][i]);
  int K;
  scanf("%d", &K);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++)
      if (ord[j][i] == K) {
        bool g = true;
        vector<int> curT;
        for (int k = 0; k < 3; k++)
          if (k != j) {
            curT.push_back(ord[k][i]);
            if (rra[ord[j][i]] > rra[ord[k][i]]) g = 0;
          }
        if (g) {
          set<int> fis, sec;
          if (curT[0] < curT[1]) swap(curT[0], curT[1]);
          for (int it = 0; it <= i; it++)
            for (int k = 0; k < 3; k++)
              if (ord[k][it] != K) {
                if (ord[k][it] <= curT[0])
                  fis.insert(ord[k][it]);
                else
                  sec.insert(ord[k][it]);
              }
          for (int it : fis) printf("%d ", it);
          for (int it = i + 1; it < n; it++)
            for (int k = 0; k < 3; k++) sec.insert(ord[k][it]);
          for (int it : sec) printf("%d ", it);
        } else
          for (int it = 1; it <= 3 * n; it++)
            if (it != K) printf("%d ", it);
        return 0;
      }
}
