public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int times = Integer.parseInt(line.trim());
			String n = "";
			for (int i = 0; i < times; i++) {
				double mass = 0;
				f = (in.readLine().trim() + " ").toCharArray();
				for (int j = 0; j < f.length - 1; j++) {
					if (!Character.isDigit(f[j + 1]))
						mass += atom(f[j]);
					else {
						n = makeNum(j + 1);
						mass += atom(f[j]) * Integer.parseInt(n);
						j += n.length();
					}
				}
				out.append(String.format(Locale.US, "%.3f", mass) + "\n");
			}
		}
		System.out.print(out);
	}