#include <bits/stdc++.h>
const double pi = acos(-1.0);
using namespace std;
inline long long MAX2(long long a, long long b) {
  return (a) > (b) ? (a) : (b);
}
inline long long MAX3(long long a, long long b, long long c) {
  return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long MIN2(long long a, long long b) {
  return (a) < (b) ? (a) : (b);
}
inline long long MIN3(long long a, long long b, long long c) {
  return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));
}
int mod = 1e9 + 7;
int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
  if (!a) {
    x = 0;
    y = 1;
    return b;
  }
  int64_t x1, y1;
  int64_t d = extGcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
inline long long addmod(long long a, long long b) {
  a = a % mod + b % mod;
  if (a > mod) a %= mod;
  return a;
}
inline long long submod(long long a, long long b) {
  a = a % mod - b % mod;
  if (a < 0) a += mod;
  return a;
}
inline long long mulmod(long long a, long long b) {
  return (a % mod * b % mod) % mod;
}
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
inline long long exp(long long a, long long b) {
  if (a == 0) return 0ll;
  long long r = 1LL;
  while (b > 0) {
    if (b & 1) {
      r = r * (a % mod);
      r = (r + mod) % mod;
    }
    b /= 2;
    a = (a % mod) * (a % mod);
    a = (a + mod) % mod;
  }
  return (r + mod) % mod;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  if (a == 0) return b;
  return gcd(b, a % b);
}
unsigned long int setbits(long long n) {
  unsigned long int count = 0;
  while (n) {
    n &= (n - 1);
    count++;
  }
  return count;
}
map<int, int> m1;
bool cmp(int x, int y) { return m1[x] < m1[y]; }
int main() {
  if (fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  int a[3 * n];
  for (long long i = (long long)(0); i < (long long)(3 * n); i++) {
    cin >> a[i];
    m1[a[i]] = i;
  }
  set<int> captain;
  vector<int> teams[n];
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    vector<int> temp(3);
    for (long long j = (long long)(0); j < (long long)(3); j++) cin >> temp[j];
    sort(temp.begin(), temp.end(), cmp);
    teams[i] = temp;
  }
  int k;
  cin >> k;
  for (int i = 0; i < n; i++) {
    captain.insert(teams[i][0]);
  }
  if (captain.find(k) == captain.end()) {
    for (long long i = (long long)(1); i < (long long)(3 * n + 1); i++) {
      if (i != k) cout << i << " ";
    }
    return 0;
  }
  set<int> before;
  int mine1 = 0;
  int mine2 = 0;
  int extra_from = 0;
  for (int i = 0; i < n; i++) {
    if (teams[i][0] == k) {
      mine1 = teams[i][1];
      mine2 = teams[i][2];
      before.insert(mine1);
      before.insert(mine2);
      extra_from = i + 1;
      break;
    }
  }
  set<int> rest;
  for (int i = 0; i < n; i++) {
    if (teams[i][0] != k) {
      for (int j = 0; j < 3; j++) {
        if (teams[i][j] < MAX2(mine1, mine2))
          before.insert(teams[i][j]);
        else {
          rest.insert(teams[i][j]);
        }
      }
    }
    if (teams[i][0] == k) break;
  }
  for (int i = extra_from; i < n; i++) {
    for (int j = 0; j < 3; j++) rest.insert(teams[i][j]);
  }
  for (auto x : before) cout << x << " ";
  for (auto x : rest) cout << x << " ";
}
