#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> q(3 * n + 1);
  for (int i = 0; i < 3 * n; i++) {
    int a;
    cin >> a;
    q[a] = i;
  }
  vector<vector<int>> v(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> v[i][j];
    }
  }
  int is;
  cin >> is;
  int team;
  int ind;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      if (v[i][j] == is) {
        team = i;
        ind = j;
      }
    }
  }
  int m = 1e9;
  for (int i = 0; i < 3; i++) {
    m = min(m, q[v[team][i]]);
  }
  if (q[is] == m) {
    vector<int> ans;
    vector<int> dop;
    int mi = 1e9;
    for (int i = 0; i < 3; i++) {
      if (v[team][i] < mi && i != ind) mi = v[team][i];
    }
    ans.push_back(mi);
    mi = 0;
    for (int i = 0; i < 3; i++) {
      if (v[team][i] > mi && i != ind) mi = v[team][i];
    }
    ans.push_back(mi);
    for (int i = 0; i < team; i++) {
      for (int j = 0; j < 3; j++) {
        if (v[i][j] < mi)
          ans.push_back(v[i][j]);
        else
          dop.push_back(v[i][j]);
      }
    }
    sort(ans.begin(), ans.end());
    for (int i = team + 1; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        dop.push_back(v[i][j]);
      }
    }
    sort(dop.begin(), dop.end());
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    for (int i = 0; i < dop.size(); i++) {
      cout << dop[i] << " ";
    }
  } else {
    for (int i = 1; i <= 3 * n; i++) {
      if (i != is) {
        cout << i << " ";
      }
    }
  }
}
