// Arup Guha
// 4/10/2020
// Solution to Code Jam Round 1A Problem: Pascal Walk
// Written in Contest, Commented afterwards.

import java.util.*;

public class b {

	public static int[][] combo;
	
	public static void main(String[] args) {
		
		// This is as much of pascal's triangle as I need.
		// Actually, I probably didn't need it, but I just typed it up.
		combo = new int[32][32];
		for (int i=0; i<32; i++) {
			combo[i][0] = 1;
			combo[i][i] = 1;
		}
		for (int i=2; i<32; i++)
			for (int j=1; j<i; j++)
				combo[i][j] = combo[i-1][j-1] + combo[i-1][j];
			
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=1; loop<=nC; loop++) {
		
			int n = stdin.nextInt();

			// Ta da!
			System.out.println("Case #"+loop+":");
			go(n);
		}
	}
	
	// Solves for n.
	public static void go(int n) {
		
		// This case is trivial just go down and left.
		if (n < 500) {
			for (int i=0; i<n; i++)
				System.out.println((i+1)+" "+1);
		}
		
		else {
			
			// I'll just aim for n-35 and then add extra 1s as needed.
			int sub = n - 35;
			if (sub%2 == 1) sub--;
			
			// Here I get sub in binary - note that each row of Pascal's Triangle adds up to a power of two.
			ArrayList<Integer> locs = new ArrayList<Integer>();
			for (int i=0; i<30; i++)
				if ((sub & (1<<i)) != 0)
					locs.add(i);
				
			// This is where I've been stored as 1000*r + c.
			ArrayList<Integer> places = new ArrayList<Integer>();
			places.add(1001);
			
			// Make sure we take all the numbers from each corresponding row in locs.
			for (int i=0; i<locs.size(); i++) {
				
				// Where I was.
				int prev = places.get(places.size()-1);
				int pR = prev/1000;
				int pC = prev%1000;
				
				// Where I want to go.
				int nextRow = locs.get(i)+1;
				
				// Crawl left
				if (pC == 1) {
					
					// Go down left side.
					for (int j=pR+1; j<=nextRow; j++)
						places.add(1000*j+1);
					
					// Walk across left to right.
					for (int j=2; j<=nextRow; j++)
						places.add(1000*nextRow+j);
				}
				
				// Crawl right.
				else {
					
					// Go down right side.
					for (int j=pR+1; j<=nextRow; j++)
						places.add(1000*j+j);
					
					// Walk across right to left.
					for (int j=nextRow-1; j>=1; j--)
						places.add(1000*nextRow+j);
				}
			}
			
			// Just add up everything I've walked through so far.
			// Pretty sure I don't need this as there's I could just figure out all the extra
			// left right walking I did, but I didn't feel like risking an off by one error in contest.
			int sum = 0;
			for (int i=0; i<places.size(); i++) {
				int code = places.get(i);
				int row = code/1000-1;
				int col = code%1000-1;
				sum += combo[row][col];
			}
	
			// How many more 1s I need.
			int need = n - sum;
			int code = places.get(places.size()-1);
			int cR = code/1000;
			int cC = code%1000;
			
			// Walk down left side to get those 1s.
			if (cC == 1) {
				for (int i=0; i<need; i++) {
					places.add(1000*(cR+i+1) + 1);
				}
			}
			
			// Or right side.
			else {
				for (int i=0; i<need; i++) {
					places.add(1000*(cR+i+1) + (cR+i+1));
				}				
			}
				
			// Output result.
			for (int i=0; i<places.size(); i++) {
				code = places.get(i);
				int r = code/1000;
				int c = code%1000;
				System.out.println(r+" "+c);
			}
		}
	}
}