#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
int main(int argc, const char *argv[]) {
  int t;
  double saw[4] = {12.01, 1.008, 16.00, 14.01};
  scanf("%d", &t);
  while (t--) {
    char s[85];
    double ans = 0;
    int num, len, tp, i = 0;
    scanf("%s", s);
    len = strlen(s);
    while (i < len) {
      switch (s[i++]) {
      case 'C':
        tp = 0;
        break;
      case 'H':
        tp = 1;
        break;
      case 'O':
        tp = 2;
        break;
      case 'N':
        tp = 3;
        break;
      }
      num = 0;
      while (isdigit(s[i])) {
        num = num * 10 + s[i] - '0';
        i++;
      }
      if (!num)
        num = 1;
      ans += num * saw[tp];
    }
    printf("%.3lf\n", ans);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xee0(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xed4(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1335 <main+0x1f5>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movl   $0x0,-0xb8(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xb0(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb0(%rbp),%eax
jge    131c <main+0x1dc>
movslq -0xb8(%rbp),%rax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xb8(%rbp)
movsbl -0xa0(%rbp,%rax,1),%eax
ff
add    $0xffffffbd,%eax
mov    %eax,%ecx
mov    %rcx,-0xc0(%rbp)
sub    $0xc,%eax
ja     1276 <main+0x136>
mov    -0xc0(%rbp),%rax
lea    0xdca(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0xb4(%rbp)
jmp    1276 <main+0x136>
movl   $0x1,-0xb4(%rbp)
jmp    1276 <main+0x136>
movl   $0x2,-0xb4(%rbp)
jmp    1276 <main+0x136>
movl   $0x3,-0xb4(%rbp)
movl   $0x0,-0xac(%rbp)
movslq -0xb8(%rbp),%rax
movsbl -0xa0(%rbp,%rax,1),%edi
ff
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12d3 <main+0x193>
imul   $0xa,-0xac(%rbp),%eax
movslq -0xb8(%rbp),%rcx
movsbl -0xa0(%rbp,%rcx,1),%ecx
ff
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0xac(%rbp)
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1280 <main+0x140>
cmpl   $0x0,-0xac(%rbp)
jne    12ea <main+0x1aa>
movl   $0x1,-0xac(%rbp)
cvtsi2sdl -0xac(%rbp),%xmm0
ff
movslq -0xb4(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm2
movsd  -0xa8(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
jmp    11e7 <main+0xa7>
movsd  -0xa8(%rbp),%xmm0
ff
lea    0xd3b(%rip),%rdi
call   1050 <printf@plt>
jmp    1197 <main+0x57>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xf0b(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1179 <main+0x39>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe80(%rip),%r14
jmp    11a7 <main+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorpd  %xmm0,%xmm0
lea    0xecb(%rip),%rdi
call   1050 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1168 <main+0x28>
lea    0xeb5(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1190 <main+0x50>
mov    %eax,%ebp
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    120b <main+0xcb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x8(%rsp),%xmm0
mov    $0x1,%r13d
xorps  %xmm1,%xmm1
cvtsi2sd %r13d,%xmm1
movslq %r15d,%rax
lea    0xe42(%rip),%rcx
mulsd  (%rcx,%rax,8),%xmm1
addsd  %xmm1,%xmm0
cmp    %ebp,%ebx
jge    1194 <main+0x54>
movslq %ebx,%rbx
movsbl 0x10(%rsp,%rbx,1),%eax
add    $0xffffffbd,%eax
cmp    $0xc,%eax
movsd  %xmm0,0x8(%rsp)
ja     1260 <main+0x120>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
xor    %r15d,%r15d
jmp    1260 <main+0x120>
nop
mov    $0x1,%r15d
jmp    1260 <main+0x120>
nopl   0x0(%rax,%rax,1)
mov    $0x3,%r15d
jmp    1260 <main+0x120>
nopl   0x0(%rax,%rax,1)
mov    $0x2,%r15d
cs nopw 0x0(%rax,%rax,1)
movsbl 0x11(%rsp,%rbx,1),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
je     11e0 <main+0xa0>
mov    %rbx,%r12
lea    0x11(%rsp),%rax
add    %rax,%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x0(%r13,%r13,4),%eax
movsbl -0x1(%r12),%ecx
lea    (%rcx,%rax,2),%r13d
add    $0xffffffd0,%r13d
movsbl (%r12),%edi
call   1030 <isdigit@plt>
add    $0x1,%ebx
add    $0x1,%r12
test   %rax,%rax
jne    1290 <main+0x150>
test   %r13d,%r13d
movsd  0x8(%rsp),%xmm0
jne    11ec <main+0xac>
jmp    11e6 <main+0xa6>

LLVM IR (-O0):
@__const.main.saw = [4 x double] [double 1.201000e+01, double 1.008000e+00, double 1.600000e+01, double 1.401000e+01]
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"%.3lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4 x double]
%8 = alloca [85 x i8]
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [4 x double]* %7 to i8*
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %16
16: ; preds = %73, %2
%17 = load i32, i32* %6
%18 = add nsw i32 %17, -1
store i32 %18, i32* %6
%19 = icmp ne i32 %17, 0
br i1 %19, label %20, label %76
20: ; preds = %16
store double 0.000000e+00, double* %9
store i32 0, i32* %13
%21 = getelementptr inbounds [85 x i8], [85 x i8]* %8, i64 0, i64 0
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [85 x i8], [85 x i8]* %8, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %11
br label %25
25: ; preds = %64, %20
%26 = load i32, i32* %13
%27 = load i32, i32* %11
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %73
29: ; preds = %25
%30 = load i32, i32* %13
%31 = add nsw i32 %30, 1
store i32 %31, i32* %13
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds [85 x i8], [85 x i8]* %8, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
switch i32 %35, label %40 [
i32 67, label %36
i32 72, label %37
i32 79, label %38
i32 78, label %39
]
36: ; preds = %29
store i32 0, i32* %12
br label %40
37: ; preds = %29
store i32 1, i32* %12
br label %40
38: ; preds = %29
store i32 2, i32* %12
br label %40
39: ; preds = %29
store i32 3, i32* %12
br label %40
40: ; preds = %29, %39, %38, %37, %36
store i32 0, i32* %10
br label %41
41: ; preds = %48, %40
%42 = load i32, i32* %13
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [85 x i8], [85 x i8]* %8, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = call i64 @isdigit(i8 signext %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %41
%49 = load i32, i32* %10
%50 = mul nsw i32 %49, 10
%51 = load i32, i32* %13
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [85 x i8], [85 x i8]* %8, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = add nsw i32 %50, %55
%57 = sub nsw i32 %56, 48
store i32 %57, i32* %10
%58 = load i32, i32* %13
%59 = add nsw i32 %58, 1
store i32 %59, i32* %13
br label %41
60: ; preds = %41
%61 = load i32, i32* %10
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %60
store i32 1, i32* %10
br label %64
64: ; preds = %63, %60
%65 = load i32, i32* %10
%66 = sitofp i32 %65 to double
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 %68
%70 = load double, double* %69
%71 = load double, double* %9
%72 = call double @llvm.fmuladd.f64(double %66, double %70, double %71)
store double %72, double* %9
br label %25
73: ; preds = %25
%74 = load double, double* %9
%75 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %74)
br label %16
76: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@__const.main.saw = [4 x double] [double 1.201000e+01, double 1.008000e+00, double 1.600000e+01, double 1.401000e+01]
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"%.3lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [85 x i8]
%5 = bitcast i32* %3 to i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = add nsw i32 %7, -1
store i32 %8, i32* %3
%9 = icmp eq i32 %7, 0
br i1 %9, label %72, label %10
10: ; preds = %2
%11 = getelementptr inbounds [85 x i8], [85 x i8]* %4, i64 0, i64 0
br label %12
12: ; preds = %10, %65
%13 = phi i32 [ undef, %10 ], [ %67, %65 ]
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%15 = call i32 @strlen(i8* %11)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %65
17: ; preds = %12, %56
%18 = phi i32 [ %57, %56 ], [ 0, %12 ]
%19 = phi i32 [ %30, %56 ], [ %13, %12 ]
%20 = phi double [ %63, %56 ], [ 0.000000e+00, %12 ]
%21 = sext i32 %18 to i64
%22 = getelementptr inbounds [85 x i8], [85 x i8]* %4, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
switch i32 %24, label %29 [
i32 67, label %25
i32 72, label %26
i32 79, label %27
i32 78, label %28
]
25: ; preds = %17
br label %29
26: ; preds = %17
br label %29
27: ; preds = %17
br label %29
28: ; preds = %17
br label %29
29: ; preds = %17, %28, %27, %26, %25
%30 = phi i32 [ %19, %17 ], [ 3, %28 ], [ 2, %27 ], [ 1, %26 ], [ 0, %25 ]
%31 = add nsw i32 %18, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [85 x i8], [85 x i8]* %4, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = call i64 @isdigit(i8 signext %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %54, label %37
37: ; preds = %29, %37
%38 = phi i64 [ %46, %37 ], [ %32, %29 ]
%39 = phi i8* [ %47, %37 ], [ %33, %29 ]
%40 = phi i32 [ %45, %37 ], [ 0, %29 ]
%41 = mul nsw i32 %40, 10
%42 = load i8, i8* %39
%43 = sext i8 %42 to i32
%44 = add i32 %41, -48
%45 = add i32 %44, %43
%46 = add i64 %38, 1
%47 = getelementptr inbounds [85 x i8], [85 x i8]* %4, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = call i64 @isdigit(i8 signext %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %37
51: ; preds = %37
%52 = trunc i64 %46 to i32
%53 = icmp eq i32 %45, 0
br i1 %53, label %54, label %56
54: ; preds = %29, %51
%55 = phi i32 [ %52, %51 ], [ %31, %29 ]
br label %56
56: ; preds = %51, %54
%57 = phi i32 [ %55, %54 ], [ %52, %51 ]
%58 = phi i32 [ 1, %54 ], [ %45, %51 ]
%59 = sitofp i32 %58 to double
%60 = sext i32 %30 to i64
%61 = getelementptr inbounds [4 x double], [4 x double]* @__const.main.saw, i64 0, i64 %60
%62 = load double, double* %61
%63 = call double @llvm.fmuladd.f64(double %59, double %62, double %20)
%64 = icmp slt i32 %57, %15
br i1 %64, label %17, label %65
65: ; preds = %56, %12
%66 = phi double [ 0.000000e+00, %12 ], [ %63, %56 ]
%67 = phi i32 [ %13, %12 ], [ %30, %56 ]
%68 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %66)
%69 = load i32, i32* %3
%70 = add nsw i32 %69, -1
store i32 %70, i32* %3
%71 = icmp eq i32 %69, 0
br i1 %71, label %72, label %12
72: ; preds = %65, %2
ret i32 0
}