// Arup Guha
// 8/22/2015
// Solution to 2015 UCF Locals Problem: Brownies vs. Candies vs. Cookies (brownie)

import java.util.*;

public class brownie {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=1; loop<=numCases; loop++) {

			int dummy = stdin.nextInt();
			int brownies = stdin.nextInt();

			// Print header.
			System.out.println("Practice #"+loop+": "+dummy+" "+brownies);
			int numGroups = stdin.nextInt();

			// Go through each group of students.
			for (int i=0; i<numGroups; i++) {

				int students = stdin.nextInt();

				// Double the brownies as long as we have to. Then give one per kid.
				while (brownies <= students) brownies <<= 1;
				brownies -=students;

				// Report.
				System.out.println(students+" "+brownies);
			}
			System.out.println();
		}
	}
}