#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 main() {
  char formula[81], temp;
  int i, T, count;
  double mass, weight['O' + 1];
  weight['C'] = 12.01;
  weight['H'] = 1.008;
  weight['N'] = 14.01;
  weight['O'] = 16.00;
  scanf("%d", &T);
  while (T--) {
    mass = 0;
    scanf("%s", formula);
    for (i = 0; formula[i]; i++) {
      temp = formula[i];
      count = 0;
      while (isdigit(formula[i + 1]))
        count = count * 10 + formula[++i] - '0';
      mass += weight[temp] * (count ? count : 1);
    }
    printf("%.3lf\n", mass);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x310,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0xe8(%rbp)
ff
movsd  0xeb6(%rip),%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  0xe9e(%rip),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
lea    0xe97(%rip),%rdi
lea    -0x6c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x6c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x6c(%rbp)
cmp    $0x0,%eax
je     12ae <main+0x17e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x68(%rbp)
movslq -0x68(%rbp),%rax
cmpb   $0x0,-0x60(%rbp,%rax,1)
je     1298 <main+0x168>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%al
mov    %al,-0x61(%rbp)
movl   $0x0,-0x70(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x60(%rbp,%rax,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1228 <main+0xf8>
imul   $0xa,-0x70(%rbp),%eax
mov    -0x68(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x68(%rbp)
movslq %ecx,%rcx
movsbl -0x60(%rbp,%rcx,1),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x70(%rbp)
jmp    11ea <main+0xba>
movsbq -0x61(%rbp),%rax
movsd  -0x300(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0x308(%rbp)
ff
cmpl   $0x0,-0x70(%rbp)
je     1256 <main+0x126>
mov    -0x70(%rbp),%eax
mov    %eax,-0x30c(%rbp)
jmp    1266 <main+0x136>
mov    $0x1,%eax
mov    %eax,-0x30c(%rbp)
jmp    1266 <main+0x136>
movsd  -0x308(%rbp),%xmm0
ff
mov    -0x30c(%rbp),%eax
cvtsi2sd %eax,%xmm2
movsd  -0x78(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11c9 <main+0x99>
movsd  -0x78(%rbp),%xmm0
lea    0xd82(%rip),%rdi
call   1040 <printf@plt>
jmp    1194 <main+0x64>
xor    %eax,%eax
add    $0x310,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2f8,%rsp
movabs $0x4028051eb851eb85,%rax
05 28 40
mov    %rax,0x288(%rsp)
movabs $0x3ff020c49ba5e354,%rax
20 f0 3f
mov    %rax,0x2b0(%rsp)
movapd 0xe93(%rip),%xmm0
movapd %xmm0,0x2e0(%rsp)
lea    0xe93(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    11a4 <main+0x74>
xor    %eax,%eax
add    $0x2f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movabs $0x100000000,%r13
lea    0xe61(%rip),%r12
jmp    11d3 <main+0xa3>
nopw   0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
mov    %r12,%rdi
call   1040 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1190 <main+0x60>
lea    0xe39(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x10(%rsp),%bpl
test   %bpl,%bpl
je     11c0 <main+0x90>
xor    %eax,%eax
xorpd  %xmm0,%xmm0
jmp    1226 <main+0xf6>
nopl   0x0(%rax,%rax,1)
mov    %r15d,%eax
mov    %rbx,%r15
movsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    0x10(%rsp,%r15,1),%bpl
test   %bpl,%bpl
je     11c4 <main+0x94>
movsd  %xmm0,0x8(%rsp)
movslq %eax,%r15
movsbl 0x11(%rsp,%r15,1),%edi
add    $0x1,%r15
call   1030 <isdigit@plt>
test   %rax,%rax
je     12b0 <main+0x180>
lea    -0x1(%r15),%ebx
shl    $0x20,%rbx
add    %r13,%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r14,%r14,4),%eax
movsbl 0x10(%rsp,%r15,1),%ecx
lea    (%rcx,%rax,2),%r14d
add    $0xffffffd0,%r14d
movsbl 0x11(%rsp,%r15,1),%edi
add    $0x1,%r15
call   1030 <isdigit@plt>
add    %r13,%rbx
test   %rax,%rax
jne    1260 <main+0x130>
sar    $0x20,%rbx
movsbq %bpl,%rax
movsd  0x70(%rsp,%rax,8),%xmm2
test   %r14d,%r14d
jne    1200 <main+0xd0>
mov    $0x1,%r14d
jmp    1200 <main+0xd0>
nopl   0x0(%rax,%rax,1)
movsbq %bpl,%rax
movsd  0x70(%rsp,%rax,8),%xmm2
mov    $0x1,%r14d
mov    %r15d,%eax
jmp    1206 <main+0xd6>

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

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