#include <bits/stdc++.h>
using namespace std;
long long int mult(long long int a, long long int b) {
  return ((a % int(1e9 + 7)) * (b % int(1e9 + 7))) % int(1e9 + 7);
}
long long int add(long long int a, long long int b) {
  return ((a % int(1e9 + 7)) + (b % int(1e9 + 7))) % int(1e9 + 7);
}
long long int subt(long long int a, long long int b) {
  long long int ans = ((a % int(1e9 + 7)) - (b % int(1e9 + 7))) % int(1e9 + 7);
  ans %= int(1e9 + 7);
  ans = (ans + int(1e9 + 7)) % int(1e9 + 7);
  return ans;
}
long long int exp(long long int a, long long int b) {
  long long int ans = 1;
  long long int po = a;
  while (b != 0) {
    if (b % 2) {
      ans = ((ans % int(1e9 + 7)) * (po % int(1e9 + 7))) % int(1e9 + 7);
    }
    po = ((po % int(1e9 + 7)) * (po % int(1e9 + 7))) % int(1e9 + 7);
    b /= 2;
  }
  return ans;
}
void solve() {
  long long int n;
  cin >> n;
  vector<vector<long long int> > slot;
  vector<long long int> ind(n, 0);
  for (int i = 0; i < n; i++) {
    long long int c;
    cin >> c;
    vector<long long int> temp(c);
    for (long long int j = 0; j < c; j++) {
      cin >> temp[j];
    }
    ind[i] = c;
    slot.push_back(temp);
  }
  long long int m;
  cin >> m;
  long long int flag = 0;
  multiset<vector<long long int> > ban;
  for (int i = 0; i < m; i++) {
    vector<long long int> temp(n);
    for (long long int j = 0; j < n; j++) {
      cin >> temp[j];
    }
    ban.insert(temp);
    if (ind == temp) {
      flag = 1;
    }
  }
  if (flag == 1) {
    set<vector<long long int> > poss;
    auto it = ban.begin();
    while (it != ban.end()) {
      vector<long long int> temp = (*it);
      for (long long int j = 0; j < n; j++) {
        if (temp[j] > 1) {
          long long int tem = temp[j];
          temp[j] = temp[j] - 1;
          if (ban.find(temp) == ban.end()) {
            poss.insert(temp);
          }
          temp[j] = tem;
        }
      }
      it++;
    }
    long long int ans = 0;
    for (auto it : poss) {
      long long int cur = 0;
      vector<long long int> v = (it);
      for (int i = 0; i < n; i++) {
        cur += (slot[i][v[i] - 1]);
      }
      if (cur >= ans) {
        for (int i = 0; i < n; i++) {
          ind[i] = v[i];
        }
        ans = cur;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ind[i] << " ";
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}
