#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p2i = pair<int, int>;
using p4i = pair<p2i, p2i>;
using p8i = pair<p4i, p4i>;
using p10i = pair<p8i, p2i>;
template <typename A>
inline A lowbit(A a) {
  return a & -a;
}
inline int read() {
  int s = 0, w = 1;
  char ch;
  while ((ch = getchar()) > '9' || ch < '0')
    if (ch == '-') w = -1;
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * w;
}
inline ll lread() {
  long long s = 0, w = 1;
  char ch;
  while ((ch = getchar()) > '9' || ch < '0')
    if (ch == '-') w = -1;
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * w;
}
inline void read(int &n, int *a, int flag = 0) {
  if (flag) n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
}
inline void read(int &n, ll *a, int flag = 0) {
  if (flag) n = read();
  for (int i = 1; i <= n; i++) a[i] = lread();
}
template <typename A>
void write(A s, char ch = 0) {
  if (s < 0) {
    s = -s;
    putchar('-');
  }
  if (s > 9) write(s / 10, 0);
  putchar(s - s / 10 * 10 + '0');
  if (ch) putchar(ch);
}
template <typename A>
inline void write(int n, A *a, char ch, bool flag = 0) {
  for (int i = (1); i <= (n); ++i) write(a[i], ch);
  if (!flag) putchar('\n');
}
int a[11][200001];
queue<p10i> que;
map<p10i, bool> vis;
map<p10i, bool> no;
int num[11];
int cnt[11];
int n, m;
p10i ans;
int ansi;
p10i make() {
  return p10i(p8i(p4i(p2i(cnt[1], cnt[2]), p2i(cnt[3], cnt[4])),
                  p4i(p2i(cnt[5], cnt[6]), p2i(cnt[7], cnt[8]))),
              p2i(cnt[9], cnt[10]));
}
p10i giao(p10i num, int x, int y) {
  if (x == 1)
    num.first.first.first.first += y;
  else if (x == 2)
    num.first.first.first.second += y;
  else if (x == 3)
    num.first.first.second.first += y;
  else if (x == 4)
    num.first.first.second.second += y;
  else if (x == 5)
    num.first.second.first.first += y;
  else if (x == 6)
    num.first.second.first.second += y;
  else if (x == 7)
    num.first.second.second.first += y;
  else if (x == 8)
    num.first.second.second.second += y;
  else if (x == 9)
    num.second.first += y;
  else
    num.second.second += y;
  return num;
}
inline int get(p10i num, int x) {
  if (x == 1)
    return num.first.first.first.first;
  else if (x == 2)
    return num.first.first.first.second;
  else if (x == 3)
    return num.first.first.second.first;
  else if (x == 4)
    return num.first.first.second.second;
  else if (x == 5)
    return num.first.second.first.first;
  else if (x == 6)
    return num.first.second.first.second;
  else if (x == 7)
    return num.first.second.second.first;
  else if (x == 8)
    return num.first.second.second.second;
  else if (x == 9)
    return num.second.first;
  else
    return num.second.second;
}
void out() {
  for (int i = 1; i <= n; i++) printf("%d ", get(ans, i));
}
void debug(p10i p) {
  for (int i = 1; i <= n; i++) printf("%d ", get(p, i));
}
signed main() {
  int t;
  t = 1;
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", num + i);
      for (int j = 1; j <= num[i]; j++) scanf("%d", a[i] + j);
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) scanf("%d", cnt + j);
      no[make()] = 1;
    }
    for (int i = 1; i <= n; i++) cnt[i] = num[i];
    p10i root = make();
    if (!no[root]) {
      for (int i = 1; i <= n; i++) printf("%d ", num[i]);
      return 0;
    }
    que.push(root);
    vis[root] = 1;
    while (!que.empty()) {
      p10i t = que.front();
      que.pop();
      for (int i = 1; i <= n; i++) {
        if (get(t, i) == 1) continue;
        p10i p = giao(t, i, -1);
        if (vis[p]) continue;
        vis[p] = 1;
        if (no[p]) {
          que.push(p);
          continue;
        }
        int num = 0;
        for (int j = 1; j <= n; j++) num += a[j][get(p, j)];
        if (num > ansi) {
          ansi = num;
          ans = p;
        }
      }
    }
    out();
  }
  return 0;
}
