#include <stdio.h>
int GetQuantity(char* q, char** p)
{
int quantity = 0;
while (*q && '0' <= *q && *q <= '9')
{
quantity = quantity*10 + (*q-'0');
++q;
}
if (quantity == 0)
quantity = 1;
*p = q;
return quantity;
}
int main()
{
int T, quantity;
double mass;
char str[81], *p;
scanf("%d", &T);
while (T--)
{
scanf("%s", str);
mass = 0.0;
p = str;
while (*p)
{
if (*p == 'C')
{
quantity = GetQuantity(p+1, &p);
mass += (12.01*quantity);
}
else if (*p == 'H')
{
quantity = GetQuantity(p+1, &p);
mass += (1.008*quantity);
}
else if (*p == 'O')
{
quantity = GetQuantity(p+1, &p);
mass += (16.00*quantity);
}
else if (*p == 'N')
{
quantity = GetQuantity(p+1, &p);
mass += (14.01*quantity);
}
else
{
++p;
}
}
printf("%.3f\n", mass);
}
return 0;
}