// Arup Guha
// 9/30/2015
// Solution to 2003 UCF HS Contest Problem: Bowling for Soup
import java.util.*;

public class bowling {

	final public static int NUMFRAMES = 10;
	final public static int ALLPINS = 10;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = Integer.parseInt(stdin.nextLine().trim());
		int loop = 1;

		// Process all cases.
		while (n != 0) {

			// Read in bowlers.
			bowler[] league = new bowler[n];
			String[] names = new String[n];
			for (int i=0; i<n; i++) {
				names[i] = stdin.nextLine().trim();
				league[i] = new bowler(names[i]);
			}

			// Now sort out scores.
			StringTokenizer tok = new StringTokenizer(stdin.nextLine());
			for (int i=1; i<=NUMFRAMES; i++) {
				for (int j=0; j<n; j++) {

					// Add this roll for sure.
					int cur = Integer.parseInt(tok.nextToken());
					int next = 0;
					league[j].rolls.add(cur);

					// No strike or last frame so we get the next one.
					if (cur < 10 || i == NUMFRAMES) {
						next = Integer.parseInt(tok.nextToken());
						league[j].rolls.add(next);
					}

					// Special case!
					if (i == NUMFRAMES && cur+next >= ALLPINS)
						league[j].rolls.add(Integer.parseInt(tok.nextToken()));
				}
			}

			// Update everyone's scores...
			for (int i=0; i<n; i++)
				league[i].setScore();

			// Sort them.
			Arrays.sort(league);

			// Print them.
			System.out.println("Lane #"+loop+":");
			for (int i=0; i<n; i++)
				System.out.println(league[i]);
			System.out.println();

			// Get next case.
			n = Integer.parseInt(stdin.nextLine().trim());
			loop++;
		}
	}
}

class bowler implements Comparable<bowler> {

	public String name;
	public ArrayList<Integer> rolls;
	public int score;

	// Create the bowler object from all the data.
	public bowler(String n) {
		name = n;
		rolls = new ArrayList<Integer>();
		score = 0;
	}

	// How we want to print a bowler.
	public String toString() {
		return " "+name+" "+score;
	}

	// Sets the score of this bowler.
	public void setScore() {

		// Process all the scores.
		int index = 0;
		for (int frame = 1; frame<=bowling.NUMFRAMES; frame++) {

			int first = rolls.get(index);

			// Got a strike - add up score in advance, then go to next frame.
			if (first == bowling.ALLPINS) {
				score += (first + rolls.get(index+1)+rolls.get(index+2));
				index++;
			}

			// Regular play.
			else {

				// Add both.
				int second = rolls.get(index+1);
				score += (first+second);

				// Update for spare.
				if (first+second == bowling.ALLPINS) score += rolls.get(index+2);

				// Update to next index.
				index += 2;
			}
		}
	}

	// Sorts in descending order of score.
	public int compareTo(bowler other) {
		return other.score - this.score;
	}

}