import java.util.Scanner;

class solution {
	public static int toScore(int last, String current) {
		if (current.equals("X")) return 10;
		if (current.equals("/")) return 10 - last;
		return Integer.parseInt(current);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = Integer.parseInt(sc.nextLine());
		for (int t = 0; t < T; ++t) {
			String[] input = sc.nextLine().split(" ");
			int[] value = new int[input.length];
			int last = 0;
			for (int i = 0; i < input.length; ++i) {
				value[i] = toScore(last, input[i]);
				last = value[i];
			}
			int score = 0;
			int pos = 0;
			// We will deal with the 10th frame later
			for (int frame = 0; frame < 9; ++frame) {
				score += value[pos] + value[pos+1];
				if (value[pos] == 10) { // strike
					score += value[pos+2];
					pos++;
				} else if (value[pos] + value[pos+1] == 10) { // spare
					score += value[pos+2];
					pos+=2;
				} else { // open frame
					pos += 2;
				}
			}
			// 10th frame, the value is simply the sum of what is left
			for (; pos < value.length; ++pos)
				score += value[pos];
			System.out.println(score);
		}
	}
}
