#include <bits/stdc++.h>
using namespace std;
int order[320000];
int team[320000][3];
bool used[320000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; i++) {
    int a;
    scanf("%d", &a);
    a--;
    order[i] = a;
  }
  for (int i = 0; i < n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--, c--;
    team[a][0] = b, team[a][1] = c;
    team[b][0] = c, team[b][1] = a;
    team[c][0] = a, team[c][1] = b;
  }
  int k;
  scanf("%d", &k);
  k--;
  int pick1, pick2;
  for (int i = 0; i < 3 * n; i++) {
    int a = order[i];
    if (used[a]) continue;
    int b = team[a][0];
    int c = team[a][1];
    used[a] = used[b] = used[c] = true;
    if (a == k) {
      pick1 = b;
      pick2 = c;
      break;
    }
    if (b == k || c == k) {
      for (int i = 0; i < 3 * n; i++)
        if (i != k) printf("%d ", i + 1);
      printf("\n");
      return 0;
    }
  }
  vector<int> first;
  vector<int> last;
  first.push_back(pick1);
  first.push_back(pick2);
  for (int i = 0; i < 3 * n; i++) {
    if (i == k || i == pick1 || i == pick2) continue;
    if (used[i]) {
      if (i < pick1 || i < pick2)
        first.push_back(i);
      else
        last.push_back(i);
    } else
      last.push_back(i);
  }
  sort(first.begin(), first.end());
  sort(last.begin(), last.end());
  for (int i = 0; i < first.size(); i++) printf("%d ", first[i] + 1);
  for (int i = 0; i < last.size(); i++) printf("%d ", last[i] + 1);
  printf("\n");
}
