n = int(input()) A = [input().split() for _ in range(n)] tot = 0 for row in A: for a in row: if a != "?": tot += int(a) if n == 1: print(1) elif n == 2: print(2 - tot) elif n == 3: print(5 - tot) elif n == 4: print(4 - tot) elif n == 5: three = False for row in A: if "3" in row: three = True break if three: print(13 - tot) else: print(8 - tot) elif n == 6: print(10 - tot) elif n == 8: print(8 - tot) elif n == 10: if tot >= 20: print(26 - tot) else: print(16 - tot)