#include<iostream>
using namespace std;
char s[105][105],chu[105][105];
char din[105];
int k1,k2;
int main()
{
din[0]='0';
int k,n,i,j,n1,n2,a,b,c,num;
cin>>n;
while(n--)
{
k=0;
i=0;
memset(s,'/',sizeof(s));
memset(chu,'/',sizeof(chu));
cin>>s[0];
do
{
k++;
cin>>s[k];
}while(strcmp(s[k],din)!=0);
num=0;
while(s[0][num]>'/')
num++;
for(j=0;j<num;j++)
chu[0][j]=s[0][j];
while(strcmp(s[i+1],din)!=0)
{
num=0;
while(chu[i][num]>'/')
num++;
k1=num;
n1=k1;
num=0;
while(s[i+1][num]>'/')
num++;
k2=num;
n2=k2;
c=0;
while(k1>=1&&k2>=1)
{
a=chu[i][k1-1]-'0';
b=s[i+1][k2-1]-'0';
if(k1>k2)
chu[i+1][k1]=(a+b+c)%10+'0';
else
chu[i+1][k2]=(a+b+c)%10+'0';
c=(a+c+b)/10;
k1--;
k2--;
}
if(k1>k2)
{
while(k1>=1)
{
a=chu[i][k1-1]-'0';
b=0;
chu[i+1][k1]=(a+b+c)%10+'0';
c=(a+c+b)/10;
k1--;
}
chu[i+1][k1]=c+'0';
}
else
{
while(k2>=1)
{
a=s[i+1][k2-1]-'0';
b=0;
chu[i+1][k2]=(a+b+c)%10+'0';
c=(a+c+b)/10;
k2--;
}
chu[i+1][k2]=c+'0';
}
while(chu[i+1][0]=='0')
{
if(n1>n2)
for(k=0;k<=n1;k++)
chu[i+1][k]=chu[i+1][k+1];
else
for(k=0;k<=n2;k++)
chu[i+1][k]=chu[i+1][k+1];
}
i++;
}
j=0;
while(chu[i][j]>'/')
{
cout<<chu[i][j];
j++;
}
cout<<endl;
if(n) cout<<endl;
}
return 0;
}