#include <bits/stdc++.h>
using namespace std;
double trans(string a)
{
stringstream ss;
ss<<a;
double t;
ss>>t;
return t;
}
double k[250];
main()
{
int n;
cin>>n;
k['O']=16.00;k['N']=14.01;
k['H']=1.008;k['C']=12.01;
while(n--)
{
string a;
cin>>a;
a=a+'K';
string st="";
double sum=0;
char ch=a[0];
for(int i=0;i<a.size();i++)
{
if(isalpha(a[i]))
{
double num=trans(st);
if(i&&st=="")
sum+=k[ch];
else
sum+=k[ch]*num;
ch=a[i];
st="";
}
if(isdigit(a[i]))
st=st+a[i];
}
printf("%.3lf\n",sum);
}
}