#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v0;
  vector<vector<long long>> a(n);
  for (long long i = 0; i < n; i++) {
    long long c;
    cin >> c;
    v0.push_back(c - 1);
    while (c--) {
      long long x;
      cin >> x;
      a[i].push_back(x);
    }
  }
  auto Val = [&](vector<long long> v) {
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      ans += a[i][v[i]];
    }
    return ans;
  };
  map<vector<long long>, long long> mp;
  long long m;
  cin >> m;
  vector<vector<long long>> b(m, vector<long long>(n));
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) {
      cin >> b[i][j];
      --b[i][j];
    }
    mp[b[i]] = 1;
  }
  if (mp.find(v0) == mp.end()) {
    for (long long x : v0) {
      cout << x + 1 << " ";
    }
    cout << '\n';
    return 0;
  }
  vector<vector<long long>> out;
  for (long long i = 0; i < m; i++) {
    auto v = b[i];
    for (long long j = 0; j < n; j++) {
      auto w = v;
      if (w[j] == 0) continue;
      --w[j];
      if (mp.find(w) != mp.end()) {
        continue;
      }
      mp[w] = 1;
      out.push_back(w);
    }
  }
  long long mx = 0;
  vector<long long> ans;
  for (auto& v : out) {
    if (Val(v) > mx) {
      mx = Val(v);
      ans = v;
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << ans[i] + 1 << " ";
  }
  cout << '\n';
  return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

Ivan is playing yet another roguelike computer game. He controls a single hero in the game. The hero has n equipment slots. There is a list of c_i items for the i-th slot, the j-th of them increases the hero strength by a_{i,j}. The items for each slot are pairwise distinct and are listed in the increasing order of their strength increase. So, a_{i,1} < a_{i,2} < ... < a_{i,c_i}.

For each slot Ivan chooses exactly one item. Let the chosen item for the i-th slot be the b_i-th item in the corresponding list. The sequence of choices [b_1, b_2, ..., b_n] is called a build.

The strength of a build is the sum of the strength increases of the items in it. Some builds are banned from the game. There is a list of m pairwise distinct banned builds. It's guaranteed that there's at least one build that's not banned.

What is the build with the maximum strength that is not banned from the game? If there are multiple builds with maximum strength, print any of them.

Input

The first line contains a single integer n (1 ≤ n ≤ 10) — the number of equipment slots.

The i-th of the next n lines contains the description of the items for the i-th slot. First, one integer c_i (1 ≤ c_i ≤ 2 ⋅ 10^5) — the number of items for the i-th slot. Then c_i integers a_{i,1}, a_{i,2}, ..., a_{i,c_i} (1 ≤ a_{i,1} < a_{i,2} < ... < a_{i,c_i} ≤ 10^8).

The sum of c_i doesn't exceed 2 ⋅ 10^5.

The next line contains a single integer m (0 ≤ m ≤ 10^5) — the number of banned builds.

Each of the next m lines contains a description of a banned build — a sequence of n integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ c_i).

The builds are pairwise distinct, and there's at least one build that's not banned.

Output

Print the build with the maximum strength that is not banned from the game. If there are multiple builds with maximum strength, print any of them.

Examples

Input


3
3 1 2 3
2 1 5
3 2 4 6
2
3 2 3
3 2 2


Output


2 2 3 


Input


3
3 1 2 3
2 1 5
3 2 4 6
2
3 2 3
2 2 3


Output


1 2 3


Input


3
3 1 2 3
2 1 5
3 2 4 6
2
3 2 3
2 2 3


Output


3 2 2


Input


4
1 10
1 4
1 7
1 3
0


Output


1 1 1 1 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v0;
  vector<vector<long long>> a(n);
  for (long long i = 0; i < n; i++) {
    long long c;
    cin >> c;
    v0.push_back(c - 1);
    while (c--) {
      long long x;
      cin >> x;
      a[i].push_back(x);
    }
  }
  auto Val = [&](vector<long long> v) {
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      ans += a[i][v[i]];
    }
    return ans;
  };
  map<vector<long long>, long long> mp;
  long long m;
  cin >> m;
  vector<vector<long long>> b(m, vector<long long>(n));
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) {
      cin >> b[i][j];
      --b[i][j];
    }
    mp[b[i]] = 1;
  }
  if (mp.find(v0) == mp.end()) {
    for (long long x : v0) {
      cout << x + 1 << " ";
    }
    cout << '\n';
    return 0;
  }
  vector<vector<long long>> out;
  for (long long i = 0; i < m; i++) {
    auto v = b[i];
    for (long long j = 0; j < n; j++) {
      auto w = v;
      if (w[j] == 0) continue;
      --w[j];
      if (mp.find(w) != mp.end()) {
        continue;
      }
      mp[w] = 1;
      out.push_back(w);
    }
  }
  long long mx = 0;
  vector<long long> ans;
  for (auto& v : out) {
    if (Val(v) > mx) {
      mx = Val(v);
      ans = v;
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << ans[i] + 1 << " ";
  }
  cout << '\n';
  return 0;
}

```