#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  int m[300000];
  for (int i = 0; i < n * 3; i++) cin >> m[i];
  int c[100000][3];
  for (int i = 0; i < n; i++) cin >> c[i][0] >> c[i][1] >> c[i][2];
  int k;
  cin >> k;
  for (int i = 0; i < n; i++) {
    if ((c[i][0] == k) || (c[i][1] == k) || (c[i][2] == k)) {
      bool capitan = false;
      for (int j = 0; j < n * 3; j++) {
        if (m[j] == k) {
          capitan = true;
          break;
        } else if ((c[i][0] == m[j]) || (c[i][1] == m[j]) || (c[i][2] == m[j]))
          break;
      }
      if (capitan) {
        int p = 0;
        int q[300000];
        sort(c[i], c[i] + 3);
        for (int j = 0; j < 3; j++)
          if (c[i][j] != k) q[p++] = c[i][j];
        for (int j = i + 1; j < n; j++)
          for (int l = 0; l < 3; l++) q[p++] = c[j][l];
        sort(q + 2, q + p);
        int v[300000];
        for (int j = 0; j < i; j++)
          for (int l = 0; l < 3; l++) v[j * 3 + l] = c[j][l];
        sort(v, v + i * 3);
        int l = 0;
        for (int j = 0; j < p; j++) {
          while ((v[l] < q[j]) && (l < 3 * i)) cout << v[l++] << " ";
          cout << q[j] << " ";
        }
        while (l < 3 * i) cout << v[l++] << " ";
        cout << endl;
      } else {
        for (int j = 1; j <= n * 3; j++)
          if (j != k) cout << j << " ";
        cout << endl;
      }
      break;
    }
  }
  return 0;
}
