#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
struct point {
  int x, y, z;
};
int main() {
  int n;
  cin >> n;
  vector<int> it, ar;
  int a[323123];
  int b[123456][3];
  for (int i = 0; i < 3 * n; i++) {
    int z;
    cin >> z;
    a[z] = i;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) cin >> b[i][j];
  int in;
  cin >> in;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++)
      if (in == b[i][j]) {
        bool yes = true;
        for (int x = 0; x < 3; x++)
          if (in != b[i][x]) {
            it.push_back(b[i][x]);
            if (a[in] > a[b[i][x]]) yes = false;
          }
        sort(it.begin(), it.end());
        if (yes) {
          for (int x = 0; x < i; x++)
            for (int y = 0; y < 3; y++)
              if (b[x][y] > it[1])
                ar.push_back(b[x][y]);
              else
                it.push_back(b[x][y]);
          for (int x = i + 1; x < n; x++)
            for (int y = 0; y < 3; y++) ar.push_back(b[x][y]);
          sort(ar.begin(), ar.end());
          sort(it.begin(), it.end());
          for (int x = 0; x < it.size(); x++) cout << it[x] << " ";
          for (int x = 0; x < ar.size(); x++) cout << ar[x] << " ";
        } else {
          for (int x = 1; x <= 3 * n; x++)
            if (x != in) cout << x << " ";
        }
      }
  return 0;
}
