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