H - Molar mass
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
double weight[300];
weight['C']=12.01;
weight['H']= 1.008;
weight['O']= 16;
weight['N']=14.01;
cin>>n;
for(int i=0;i<n;i++){
string s;
cin>>s;
double sum=0,count=0,price=0;
for(int j=0;j<s.size();j++){
char cc[20]={'\0'};
int t=0;
price = weight[s[j++]];
while(s[j]>='0'&&s[j]<='9')
cc[t++]=s[j++];
j--;
if(t>0)count = atof(cc);
else count=1;
sum+=count*price;
}
printf("%.3lf\n",sum);
}
return 0;
}