#include <bits/stdc++.h>
using namespace std;
int a[100010][3], b[300010];
int main() {
  int i, j, k, l, m, n, nn;
  while (scanf("%d", &n) != EOF) {
    nn = 3 * n;
    vector<int> c, d;
    for (i = 1; i <= nn; i++) {
      scanf("%d", &k);
      b[k] = i;
    }
    for (i = 1; i <= n; i++) scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
    scanf("%d", &m);
    for (i = 1; i <= n; i++) {
      for (j = 0; j < 3; j++)
        if (a[i][j] == m) break;
      if (j < 3) break;
    }
    int tmp;
    tmp = a[i][j];
    a[i][j] = a[i][0];
    a[i][0] = tmp;
    if (b[a[i][0]] < b[a[i][1]] && b[a[i][0]] < b[a[i][2]]) {
      int p;
      p = max(a[i][1], a[i][2]);
      for (l = 1; l < i; l++) {
        c.push_back(a[l][0]);
        c.push_back(a[l][1]);
        c.push_back(a[l][2]);
      }
      c.push_back(a[i][1]);
      c.push_back(a[i][2]);
      for (l = i + 1; l <= n; l++) {
        d.push_back(a[l][0]);
        d.push_back(a[l][1]);
        d.push_back(a[l][2]);
      }
      sort(c.begin(), c.end());
      vector<int> e;
      for (i = 0; c[i] <= p; i++) e.push_back(c[i]);
      for (; i < c.size(); i++) d.push_back(c[i]);
      sort(d.begin(), d.end());
      for (i = 0; i < d.size(); i++) e.push_back(d[i]);
      for (i = 0; i < e.size(); i++) {
        printf("%d", e[i]);
        if (i == e.size() - 1)
          puts("");
        else
          putchar(' ');
      }
    } else {
      for (i = 1; i <= nn; i++)
        if (i != m) c.push_back(i);
      for (i = 0; i < c.size(); i++) {
        printf("%d", c[i]);
        if (i == c.size() - 1)
          puts("");
        else
          putchar(' ');
      }
    }
  }
}
