#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int t;
int n,m;
int num1[];
int num2[];
priority_queue<int,deque<int>,less<int> > big;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
for(int i=;i<n;i++)
scanf("%d",&num1[i]);
sort(num1,num1+n);
for(int i=;i<m;i++)
{
for(int j=;j<n;j++)
{
scanf("%d",&num2[j]);
big.push(num1[]+num2[j]);
}
sort(num2,num2+n);
for(int k=;k<n;k++)
for(int l=;l<n;l++)
{
if(num1[k]+num2[l]>big.top())
break;
big.pop();
big.push(num1[k]+num2[l]);
}
for(int k=;k<n;k++)
{
num1[n-k-]=big.top();
big.pop();
}
}
printf("%d",num1[]);
for(int i=;i<n;i++)
printf(" %d",num1[i]);
puts("");
}
}