t=int(input()) s=0 for i in range(t): n,m=map(int,input().split()) for j in range(n): a=list(map(int,input().split())) s+=sum(a) print(s) s=0