#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300100;
int n, ar[MAXN], k;
pair<int, int> adj[MAXN];
bool in[MAXN], in2[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
  cin >> n;
  for (int i = 0; i < 3 * n; i++) cin >> ar[i];
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    adj[a] = pair<int, int>(b, c);
    adj[b] = pair<int, int>(a, c);
    adj[c] = pair<int, int>(a, b);
  }
  cin >> k;
  for (int i = 0; i < 3 * n; i++) {
    int x = ar[i];
    if (in[x]) {
      if (x == k) {
        for (int j = 1; j <= 3 * n; j++)
          if (j != k) cout << j << ' ';
      }
      in[x] = 1;
    } else {
      if (x == k) {
        int cnt = 0;
        for (int j = 1; j <= 3 * n; j++)
          if (j != k)
            if (in[j])
              in2[j] = 1, cout << j << ' ';
            else if (j == adj[x].first || j == adj[x].second) {
              in2[j] = 1, cout << j << ' ';
              cnt++;
              if (cnt == 2) break;
            }
        for (int j = 1; j <= 3 * n; j++)
          if (j != k)
            if (!in2[j]) cout << j << ' ';
      }
      in[x] = 1;
      in[adj[x].first] = 1;
      in[adj[x].second] = 1;
    }
  }
  return 0;
}
