import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 n = ii() ABCDE = [li() for _ in range(n)] sgn = [[0] * 32 for i in range(n)] for i in range(n): a = ABCDE[i] for bit in range(32): for j in range(5): if 1 & (bit >> j): sgn[i][bit] -= a[j] else: sgn[i][bit] += a[j] ans = [0] * n sgnmaxi = [-inf] * 32 for i in range(n): for j in range(32): sgnmaxi[j] = max(sgnmaxi[j], sgn[i][j]) for i in range(n): for j in range(32): ans[i] = max(ans[i], sgn[i][j] + sgnmaxi[31 ^ j]) for v in ans: print(v)