/***
* ii. ;9ABH,
* SA391, .r9GG35&G
* &#ii13Gh; i3X31i;:,rB1
* iMs,:,i5895, .5G91:,:;:s1:8A
* 33::::,,;5G5, ,58Si,,:::,sHX;iH1
* Sr.,:;rs13BBX35hh11511h5Shhh5S3GAXS:.,,::,,1AG3i,GG
* .G51S511sr;;iiiishS8G89Shsrrsh59S;.,,,,,..5A85Si,h8
* :SB9s:,............................,,,.,,,SASh53h,1G.
* .r18S;..,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....,,.1H315199,rX,
* ;S89s,..,,,,,,,,,,,,,,,,,,,,,,,....,,.......,,,;r1ShS8,;Xi
* i55s:.........,,,,,,,,,,,,,,,,.,,,......,.....,,....r9&5.:X1
* ii55s:.........,,,,,,,,,,,,,,,,.,,,......,.....,,....r9&5.:X1
* 59;.....,. .,,,,,,,,,,,... .............,..:1;.:&s
* s8,..;53S5S3s. .,,,,,,,.,.. i15S5h1:.........,,,..,,:99
* 93.:39s:rSGB@A; ..,,,,..... .SG3hhh9G&BGi..,,,,,,,,,,,,.,83
* G5.G8 9#@@@@@X. .,,,,,,..... iA9,.S&B###@@Mr...,,,,,,,,..,.;Xh
* Gs.X8 S@@@@@@@B:..,,,,,,,,,,. rA1 ,A@@@@@@@@@H:........,,,,,,.iX:
* ;9. ,8A#@@@@@@#5,.,,,,,,,,,... 9A. 8@@@@@@@@@@M; ....,,,,,,,,S8
* X3 iS8XAHH8s.,,,,,,,,,,...,..58hH@@@@@@@@@Hs ...,,,,,,,:Gs
* r8, ,,,...,,,,,,,,,,..... ,h8XABMMHX3r. .,,,,,,,.rX:
* :9, . .:,..,:;;;::,.,,,,,.. .,,. ..,,,,,,.59
* .Si ,:.i8HBMMMMMB&5,.... . .,,,,,.sMr
* SS :: h@@@@@@@@@@#; . ... . ..,,,,iM5
* 91 . ;:.,1&@@@@@@MXs. . .,,:,:&S
* hS .... .:;,,,i3MMS1;..,..... . . ... ..,:,.99
* ,8; ..... .,:,..,8Ms:;,,,... .,::.83
* s&: .... .sS553B@@HX3s;,. .,;13h. .:::&1
* SXr . ...;s3G99XA&X88Shss11155hi. ,;:h&,
* iH8: . .. ,;iiii;,::,,,,,. .;irHA
* ,8X5; . ....... ,;iihS8Gi
* 1831, .,;irrrrrs&@
* ;5A8r. .:;iiiiirrss1H
* :X@H3s....... .,:;iii;iiiiirsrh
* r#h:;,...,,.. .,,:;;;;;:::,... .:;;;;;;iiiirrss1
* ,M8 ..,....,.....,,::::::,,... . .,;;;iiiiiirss11h
* 8B;.,,,,,,,.,..... . .. .:;;;;iirrsss111h
* i@5,:::,,,,,,,,.... . . .:::;;;;;irrrss111111
* 9Bi,:,,,,...... ..r91;;;;;iirrsss1ss1111
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
const int maxn = 1010;
void asd(int x[], char y[])
{
int len = strlen(y);
for (int i = 0; i < len; i++)
{
x[i] = y[i] - '0';
}
}
stack<int> sa, sb, sc, sd, ans;
int main()
{
ll T;
int a[100], b[100], c[100], d[100];
char aa[100], bb[100], cc[100], dd[100];
int la, lb, lc, ld;
cin >> T;
while (T--)
{
scanf("%s %s %s %s", aa, bb, cc, dd);
la = strlen(aa);
lb = strlen(bb);
lc = strlen(cc);
ld = strlen(dd);
asd(a, aa);
asd(b, bb);
asd(c, cc);
asd(d, dd);
for (int i = 0; i < la; i++)
sa.push(a[i]);
for (int i = 0; i < lb; i++)
sb.push(b[i]);
for (int i = 0; i < lc; i++)
sc.push(c[i]);
for (int i = 0; i < ld; i++)
sd.push(d[i]);
int pir = 0;
for (;;)
{
if (sa.empty() && sb.empty() && sc.empty() && sd.empty())
break;
int aaa = 0, bbb = 0, ccc = 0, ddd = 0;
if (!sa.empty())
{
aaa = sa.top();
sa.pop();
}
if (!sb.empty())
{
bbb = sb.top();
sb.pop();
}
if (!sc.empty())
{
ccc = sc.top();
sc.pop();
}
if (!sd.empty())
{
ddd = sd.top();
sd.pop();
}
int sum = aaa + bbb + ccc + ddd;
ans.push((sum+pir)%10);
pir = (sum+pir) / 10;
}
if(pir!=0)
ans.push(pir);
while (!ans.empty())
{
cout << ans.top();
ans.pop();
}
cout << endl;
}
return 0;
}