#include <bits/stdc++.h>
using namespace std;
int n;
int a[500], ans[500], cur[500];
int val[500][500], p[500][500];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) scanf("%d", &p[i][j]), val[i][p[i][j]] = j;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n; i++) ans[i] = n, cur[i] = n;
  for (int i = 1, j, k, q; i <= n; i++) {
    for (k = 0; a[k] > i; k++)
      ;
    for (j = 0; j < n; j++)
      if (a[k] != j + 1) {
        if (cur[j] >= val[j][a[k]]) cur[j] = val[j][a[k]], ans[j] = i;
      } else
        for (q = k + 1; q < n; q++)
          if (a[q] <= i) {
            if (cur[j] >= val[j][a[q]]) cur[j] = val[j][a[q]], ans[j] = i;
            break;
          }
  }
  for (int i = 0; i < n; i++) printf("%d%c", ans[i], " \n"[i + 1 == n]);
  return 0;
}
