#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<vector<long long>> a(n);
  for (long long i = 0; i < n; ++i) {
    long long c;
    cin >> c;
    for (long long j = 0; j < c; ++j) {
      long long o;
      cin >> o;
      a[i].push_back(o);
    }
  }
  set<vector<long long>> st;
  long long m;
  cin >> m;
  for (long long k = 0; k < m; ++k) {
    vector<long long> b(n);
    for (long long i = 0; i < n; ++i) {
      cin >> b[i];
      b[i]--;
    }
    st.insert(b);
  }
  set<pair<long long, vector<long long>>> all;
  map<vector<long long>, long long> dist;
  vector<long long> add(n);
  long long sum = 0;
  for (long long l = 0; l < n; ++l) {
    add[l] = a[l].size() - 1;
    sum += a[l][add[l]];
  }
  all.insert({-sum, add});
  while (all.size() != 0) {
    auto tmp = *all.begin();
    all.erase(all.begin());
    if (st.count(tmp.second) == 0) {
      for (long long i = 0; i < tmp.second.size(); ++i) {
        cout << tmp.second[i] + 1 << " ";
      }
      exit(0);
    }
    vector<long long> next = tmp.second;
    for (long long i = 0; i < n; ++i) {
      if (tmp.second[i] != 0) {
        next[i]--;
        long long res =
            tmp.first + a[i][tmp.second[i]] - a[i][tmp.second[i] - 1];
        if (dist.count(next) == 0 || dist[next] > res) {
          all.erase({dist[next], next});
          dist[next] = res;
          all.insert({dist[next], next});
        }
        next[i]++;
      }
    }
  }
}
