#include <bits/stdc++.h>
using namespace std;
const int SIZE = 100001;
int a[3 * SIZE], b[3 * SIZE], tbl[SIZE][3];
vector<int> res1, res2;
int n;
bool cmp(int k1, int k2) {
  for (int i = 0; i < n * 3; i++) {
    if (b[i] == k1) return 1;
    if (b[i] == k2) return 0;
  }
}
int main() {
  int k;
  cin >> n;
  for (int i = 0; i < 3 * n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    cin >> tbl[i][0] >> tbl[i][1] >> tbl[i][2];
  }
  cin >> k;
  int num;
  for (int i = 0; i < n; i++)
    if (tbl[i][0] == k || tbl[i][1] == k || tbl[i][2] == k) num = i;
  for (int i = 0; i <= num; i++)
    for (int j = 0; j < 3; j++)
      if (tbl[i][j] != k) res1.push_back(tbl[i][j]);
  for (int i = num + 1; i < n; i++)
    for (int j = 0; j < 3; j++) res2.push_back(tbl[i][j]);
  if (!(cmp(k, tbl[num][0]) && cmp(k, tbl[num][1]) && cmp(k, tbl[num][2]))) {
    for (int i = 0; i < res2.size(); i++) res1.push_back(res2[i]);
    sort(res1.begin(), res1.end());
    for (int i = 0; i < res1.size(); i++) cout << res1[i] << ' ';
    return 0;
  } else {
    sort(res1.begin(), res1.end());
    int i = res1.size() - 1;
    while (res1[i] != tbl[num][0] && res1[i] != tbl[num][1] &&
           res1[i] != tbl[num][2]) {
      res2.push_back(res1[i]);
      res1.pop_back();
      i--;
    }
    sort(res2.begin(), res2.end());
    for (int i = 0; i < res1.size(); i++) cout << res1[i] << ' ';
    for (int i = 0; i < res2.size(); i++) cout << res2[i] << ' ';
    return 0;
  }
}
