#include<stdio.h>
int tri(int,int,int);
int a[100][100];
int s1,s2,val1,val;
main()
{
int m,n,i,j,sum,k;
scanf("%d",&m);
for(k=1;k<=m;k++)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{ for(j=1;j<=i;j++)
scanf("%d",&a[i][j]);
printf("\n");
}
sum=tri(1,1,n);
printf("%d",sum);
}
return 0;
}
int tri(int i,int j,int n)
{
if(i>=(n+1))
return a[i][j];
else{
s1=tri(i+1,j,n);
s2=tri(i+1,j+1,n);
val1=(s1>s2?s1:s2);
val=a[i][j]+val1;
return val;
}}