Your body is built from proteins that are necessary for biological activity. If a protein is a building, an amino acid is one of its bricks. Most muscle and cell tissue is made of amino acids, and they carry out important jobs in the body such as organizing cells. The core elements of an amino acid are carbon (C), hydrogen (H), oxygen (O), nitrogen (N), and sulfur (S).
Write a program that reads the chemical formula of an amino acid and computes its molecular weight.
For example, the formula of alanine is O2C3NH7, which has 2 oxygen atoms, 3 carbon atoms, 1 nitrogen atom, and 7 hydrogen atoms. The number written after an element symbol is the count of that element, and a missing number means one atom.
The atomic weight of each element is:
The molecular weight of alanine is then computed like this.
2×15.9994+3×12.011+1×14.00674+7×1.00794=89.09412
The same method gives 149.21388 for methionine, C5H11NO2S.
The first line has the number of test cases n (1≤n≤100). Each of the next n lines has one chemical formula of an amino acid. A formula is made of letters for element symbols and digits for counts, and its length is under 100 characters. The same element can appear several times in one formula, and a character other than C, H, O, N, and S can appear as well.
For each formula print the molecular weight on its own line, rounded at the fifth decimal place and given to four decimal places. When the same element appears several times, add up all of its counts. If the formula holds a character other than C, H, O, N, and S, print Invalid formula on that line instead.