#include<stdio.h>
#include<string.h>
#include<ctype.h>
char element[] = {'C','H','O','N'};
double mass[] = {12.01, 1.008, 16.00, 14.01};
const int maxn = 100;
int main(){
int T;
scanf("%d",&T);
//char str[maxn];
while(T--){
char str[maxn];
double massSum=0;
scanf("%s",str);
//对于某一位,先判断是字母还是数字!
for(int i=0; i<strlen(str); i++){
int count=0;
int index;
if(isalpha(str[i])){
for(int j=0; j<4; j++){
if(str[i] == element[j])
index = j;
}
if(!isdigit(str[i+1]))
count = 1;
}
while(isdigit(str[i])){
count = count*10 + (str[i] - '0');
if(i<strlen(str) && isdigit(str[i+1])){
i++;
}
else
break;
}
massSum += mass[index] * count;
}
printf("%.3f\n",massSum);
}
return 0;
}
08-24
08-24