#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, person;
  int tm1, tm2, last_member;
  int tm1_value, tm2_value;
  int k_ind;
  vector<int> people;
  vector<int> trainings;
  list<int> priority_list;
  list<int>::iterator member_one, member_two, itmp;
  scanf("%d", &n);
  people.assign(3 * n, 0);
  trainings.assign(3 * n, 0);
  for (int i = 0; i < 3 * n; ++i) {
    scanf("%d", &person);
    trainings[--person] = i;
  }
  for (int i = 0; i < 3 * n; ++i) {
    scanf("%d", &people[i]);
    --people[i];
  }
  scanf("%d", &k);
  --k;
  k_ind = find(people.begin(), people.end(), k) - people.begin();
  if (k_ind % 3 == 0) {
    tm1 = k_ind + 1;
    tm2 = k_ind + 2;
  } else if (k_ind % 3 == 1) {
    tm1 = k_ind - 1;
    tm2 = k_ind + 1;
  } else {
    tm1 = k_ind - 2;
    tm2 = k_ind - 1;
  }
  tm1_value = people[tm1];
  tm2_value = people[tm2];
  if (trainings[k] < trainings[tm1_value] &&
      trainings[k] < trainings[tm2_value]) {
    last_member = max(k_ind, max(tm1, tm2));
    sort(people.begin(), people.begin() + last_member + 1);
    if (tm1_value < tm2_value) {
      priority_list.push_front(tm1_value);
      priority_list.push_back(tm2_value);
    } else {
      priority_list.push_front(tm2_value);
      priority_list.push_back(tm1_value);
    }
    member_one = priority_list.begin();
    member_two = member_one;
    ++member_two;
    for (int i = 0; i <= last_member; ++i) {
      if (people[i] == *member_one || people[i] == *member_two ||
          people[i] == k)
        continue;
      if (people[i] < *member_one) {
        priority_list.insert(member_one, people[i]);
      } else if (people[i] < *member_two) {
        priority_list.insert(member_two, people[i]);
      } else {
        priority_list.push_back(people[i]);
      }
    }
    sort(people.begin() + last_member + 1, people.end());
    itmp = member_two;
    ++itmp;
    for (int i = last_member + 1; i < 3 * n; ++i) {
      while (itmp != priority_list.end() && people[i] > *itmp) ++itmp;
      priority_list.insert(itmp, people[i]);
    }
    for (list<int>::iterator it = priority_list.begin();
         it != priority_list.end(); ++it) {
      printf("%d ", *it + 1);
    }
    printf("\n");
  } else {
    ++k;
    for (int i = 1; i <= 3 * n; ++i) {
      if (i != k) printf("%d ", i);
    }
    printf("\n");
  }
  return 0;
}
