This page is still under construction.

Parts of this page are still being built. What you see may change.

Molar Mass

Time limit1sMemory limit128 MB

Summary
The program parses each formula of C, H, O, and N with optional atom counts and prints its molar mass using the given weights.
Level

Easy2 of 10

Topics
String, Implementation
Solved
No attempts yet

Problem

An organic compound is any member of a large class of chemical compounds whose molecules contain carbon. The molar mass of an organic compound is the mass of one mole of that compound, and it can be computed from the standard atomic weights of the elements.

Given a molecular formula, Dr. CHON wants to find its molar mass. A molecular formula such as C3H4O3 identifies each constituent element by its chemical symbol and gives the number of atoms of that element in one molecule of the compound. When a molecule contains more than one atom of an element, the count is written as a subscript after the chemical symbol.

In this problem, assume that a molecular formula is made up of only the four elements 'C' (carbon), 'H' (hydrogen), 'O' (oxygen), and 'N' (nitrogen), and contains no parentheses.

The table below gives the standard atomic weights of 'C', 'H', 'O', and 'N'.

ElementCarbon (C)Hydrogen (H)Oxygen (O)Nitrogen (N)
Standard atomic weight12.01 g/mol1.008 g/mol16.00 g/mol14.01 g/mol

For example, the molar mass of the formula C6H5OH is 6×12.01+6×1.008+1×16.00=94.1086 \times 12.01 + 6 \times 1.008 + 1 \times 16.00 = 94.108 g/mol. Given a molecular formula, write a program that computes its molar mass.

Input

Your program reads from standard input. The input consists of TT test cases. The number of test cases TT is given on the first line. Each test case is given on a single line containing one molecular formula as a string. Chemical symbols are given as capital letters, and the length of the string is greater than 0 and less than 80. The count nn that follows a chemical symbol is omitted when it is 1; otherwise 2≤n≤992 \le n \le 99.

Output

Your program writes to standard output. Print exactly one line for each test case. The line contains the molar mass of the given molecular formula, printed to exactly three decimal places.

Examples4

  1. Example 1

    Input
    4
    C
    C6H5OH
    NH2CH2COOH
    C12H22O11
    
    Expected output
    12.010
    94.108
    75.070
    342.296
    
  2. Example 2

    Input
    4
    H
    O
    N
    C
    
    Expected output
    1.008
    16.000
    14.010
    12.010
    
  3. Example 3

    Input
    3
    H2O
    CO2
    NH3
    
    Expected output
    18.016
    44.010
    17.034
    
  4. Example 4

    Input
    1
    C8H10N4O2
    
    Expected output
    194.200