// Arup Guha
// 4/12/2019
// Solution to Code Jam Round 1A Problem: Pylons, SMALL VERSION ONLY (written in contest, commented later)

import java.util.*;

public class bsmall {
	
	public static int r;
	public static int c;

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process eachc ase.
		for (int loop=1; loop<=nC; loop++) {
			
			// Try to solve it via backtracking.
			r = stdin.nextInt();
			c = stdin.nextInt();
			int[][] ans = solve();
			
			// Can't do it.
			if (ans == null)
				System.out.println("Case #"+loop+": IMPOSSIBLE");
			
			// Ta da!
			else {
				System.out.println("Case #"+loop+": POSSIBLE");
				for (int i=1; i<=r*c; i++) {
					int x = -1, y = -1;
					for (int j=0; j<r*c; j++) {
						if (ans[j/c][j%c] == i) {
							x = j/c;
							y = j%c;
							break;
						}
					}
					System.out.println((x+1)+" "+(y+1));
				}
			}
		}
	}
	
	// Wrapper function that tries starting at each possible starting slot.
	public static int[][] solve() {
		for (int i=0; i<r*c; i++) {
			int[][] grid = new int[r][c];			
			boolean res = go(grid, i/c, i%c, 1);
			if (res) return grid;
		}
		return null;
	}
	
	public static boolean go(int[][] grid, int x, int y, int cur) {
		
		// Place the current number in the grid. If we're done, return!
		grid[x][y] = cur;
		if (cur == r*c) return true;
		
		// Try going everywhere next.
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {
				
				// Can't do a row, column or diagonal of the previous location.
				if (i == x || j == y || Math.abs(i-x) == Math.abs(j-y)) continue;
				
				// Can't go somewhere we've been before.
				if (grid[i][j] != 0) continue;
				
				// Recurse...
				boolean res = go(grid, i, j, cur+1);
				
				// Cut out if this worked.
				if (res) return true;
			}
		}
		
		// Undo...
		grid[x][y] = 0;
		return false;
	}
}