description: 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 
solution: import sys, os
  from io import BytesIO, IOBase
  from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
  from collections import defaultdict as dd, deque
  from heapq import merge, heapify, heappop, heappush, nsmallest
  from bisect import bisect_left as bl, bisect_right as br, bisect
   
  # region fastio
  BUFSIZE = 8192
   
  class FastIO(IOBase):
      newlines = 0
   
      def __init__(self, file):
          self._fd = file.fileno()
          self.buffer = BytesIO()
          self.writable = "x" in file.mode or "r" not in file.mode
          self.write = self.buffer.write if self.writable else None
   
      def read(self):
          while True:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              if not b:
                  break
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines = 0
          return self.buffer.read()
   
      def readline(self):
          while self.newlines == 0:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              self.newlines = b.count(b"\n") + (not b)
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines -= 1
          return self.buffer.readline()
   
      def flush(self):
          if self.writable:
              os.write(self._fd, self.buffer.getvalue())
              self.buffer.truncate(0), self.buffer.seek(0)
   
  class IOWrapper(IOBase):
      def __init__(self, file):
          self.buffer = FastIO(file)
          self.flush = self.buffer.flush
          self.writable = self.buffer.writable
          self.write = lambda s: self.buffer.write(s.encode("ascii"))
          self.read = lambda: self.buffer.read().decode("ascii")
          self.readline = lambda: self.buffer.readline().decode("ascii")
   
  stdin, stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) 
   
  mod = pow(10, 9) + 7
  mod2 = 998244353
          
  def inp(): return stdin.readline().strip()
  def iinp(): return int(inp())
  def out(var, end="\n"): stdout.write(str(var)+"\n")
  def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
  def lmp(): return list(mp())
  def mp(): return map(int, inp().split())
  def l1d(n, val=0): return [val for i in range(n)]
  def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
  def ceil(a, b): return (a+b-1)//b
  S1 = 'abcdefghijklmnopqrstuvwxyz'
  S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  def isprime(x):
      if x<=1: return False
      if x in (2, 3): return True
      if x%2 == 0: return False
      for i in range(3, int(sqrt(x))+1, 2):
          if x%i == 0: return False
      return True
   
  n = iinp()
  builds = [lmp()[1:] for i in range(n)]
  m = iinp()
  wrong = set([tuple(mp()) for i in range(m)])
  tup = tuple(len(i) for i in builds)
  hp = [(-sum(tup), tup)]
  tot = set([tup])
  while hp:
      sm1, tup = heappop(hp)
      if tup not in wrong:
          print(*tup)
          break   
      l = list(tup)
      for i in range(n):
          sm = -sm1
          lis = l.copy()
          if lis[i] == 1:
              continue
          lis[i] -= 1
          sm += builds[i][lis[i]-1] - builds[i][lis[i]]
          tup = tuple(lis)
          if tup not in tot:
              tot.add(tup)
              heappush(hp, (-sm, tup))
  