/*
* UVA_10013.cpp
*
* Created on: 2013年10月29日
* Author: Administrator
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int ans[1000005];
int main() {
int t;
scanf("%d", &t);
while (t--) {
memset(ans, 0, sizeof(ans));
int M;
scanf("%d", &M);
int j;
for (j = M - 1; j >= 0; --j) {//由高位到底为处理一遍
int num1, num2;
scanf("%d%d", &num1, &num2);
ans[j] += num1 + num2;
ans[j + 1] += ans[j] / 10;
ans[j] %= 10;
}
for(j = 0 ; j < M ;++j){//由地位到高位处理一遍
ans[j+1] += ans[j]/10;
ans[j] %= 10;
}
if (ans[M]) {//判断最高位是否有进位
M++;
}
for (j = M - 1; j >= 0; --j) {//由高位到低位输出结果
printf("%d", ans[j]);
}
printf("\n");
if (t > 0) {
printf("\n");
}
}
return 0;
}