#include<bits/stdc++.h>
using namespace std;
#define int long long
bool valid(int n){
// check palindrome
int temp = n, rev = 0;
while(temp > 0){
rev = rev * 10 + temp % 10;
temp /= 10;
}
return n == rev; // return true if n is a palindrome
}
void sol(){
int n;
cin >> n;
int a[n];
for(int &i:a) cin >> i;
int mx = 0;
for(int i = 0; i < n; i++){
if(valid(a[i])) mx += a[i];
}
cout << mx << endl;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while(t--){
sol();
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCmJvb2wgdmFsaWQoaW50IG4pewogICAgLy8gY2hlY2sgcGFsaW5kcm9tZQogICAgaW50IHRlbXAgPSBuLCByZXYgPSAwOwogICAgd2hpbGUodGVtcCA+IDApewogICAgICAgIHJldiA9IHJldiAqIDEwICsgdGVtcCAlIDEwOwogICAgICAgIHRlbXAgLz0gMTA7CiAgICB9CiAgICByZXR1cm4gbiA9PSByZXY7IC8vIHJldHVybiB0cnVlIGlmIG4gaXMgYSBwYWxpbmRyb21lCn0Kdm9pZCBzb2woKXsKICAgIGludCBuOwogICAgY2luID4+IG47CiAgICBpbnQgYVtuXTsKICAgIGZvcihpbnQgJmk6YSkgY2luID4+IGk7CiAgICBpbnQgbXggPSAwOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CiAgICAgICAgaWYodmFsaWQoYVtpXSkpIG14ICs9IGFbaV07CiAgICB9CiAgICBjb3V0IDw8IG14IDw8IGVuZGw7Cn0Kc2lnbmVkIG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShOVUxMKTsKICAgIGNvdXQudGllKE5VTEwpOwogICAgaW50IHQgPSAxOwogICAgY2luID4+IHQ7CiAgICB3aGlsZSh0LS0pewogICAgICAgIHNvbCgpOwogICAgfQogICAgcmV0dXJuIDA7Cn0=