#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int a[15][15];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(a,-1,sizeof a);
for(int i = 1; i <=9; i+=2)
for(int j = 1; j <= i; j+=2)
scanf("%d",&a[i][j]);
//求最下面四个
a[9][2] = ( a[7][1]-a[9][1]-a[9][3])/2;
a[9][4] = ( a[7][3]-a[9][3]-a[9][5])/2;
a[9][6] = ( a[7][5]-a[9][5]-a[9][7])/2;
a[9][8] = ( a[7][7]-a[9][7]-a[9][9])/2;
for(int i = 8;i>=1; i--)
for(int j =1;j <= i;j++)
if(a[i][j]==-1)
a[i][j] = a[i+1][j]+a[i+1][j+1];
for(int i = 1; i <= 9; i++)
{
for(int j = 1; j <= i; j++)
{
if(j == 1)
printf("%d",a[i][j]);
else
printf(" %d",a[i][j]);
}
cout<<endl;
}
}
return 0;
}