Organizing Containers of Balls

  • + 0 comments
    for _ in range(int(input())):
        n = int(input())
        arr = [list(map(int,input().split())) for i in range(n)]
        tot_balls = [sum([arr[i][j] for j in range(n)]) for i in range(n)]
        col_balls = [sum([arr[j][i] for j in range(n)]) for i in range(n)]
        print('Possible' if sorted(tot_balls)==sorted(col_balls) else 'Impossible')