#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
while(n){
int m,k=0;
cin>>m;
int *a = new int[m];
for(int i=0;i<m;i++){
cin>>a[i];
if(a[i]<=1 && a[i]>=100)
a[i]=0;
}
for(int j=0;j<m;j++){
int h=a[j]%16;
if(h<=7)
k-=h;
else if(h>=8)
k+=16-h;
}
cout<<k<<endl;
n--;
}
return 0;
}
using namespace std;
int main(){
int n;
cin>>n;
while(n){
int m,k=0;
cin>>m;
int *a = new int[m];
for(int i=0;i<m;i++){
cin>>a[i];
if(a[i]<=1 && a[i]>=100)
a[i]=0;
}
for(int j=0;j<m;j++){
int h=a[j]%16;
if(h<=7)
k-=h;
else if(h>=8)
k+=16-h;
}
cout<<k<<endl;
n--;
}
return 0;
}