// Arup Guha
// 10/8/08
// Solution to COP 3223 Sec. 3 - Extra Credit for Experienced Programmers
// Problem: Free

#include <stdio.h>
#include <math.h>

struct coord {
    int x;
    int y;
};

#define MAX_LENGTH 30

int main() {
    
    int numcases, n, numbombs;
    int i, j;
    int x, y;
    FILE *fin;

    // Open the input file.    
    fin = fopen("free.in", "r");
    
    fscanf(fin, "%d", &numcases);
    
    // Process each case.
    for (i=1; i<=numcases; i++) {
    
        // Read in size of the board & number of bombs
        fscanf(fin, "%d", &n);    
        fscanf(fin, "%d", &numbombs);
        
        struct coord bombs[MAX_LENGTH*MAX_LENGTH];
        
        // Read in all the bomb locations.
        for (j=0; j<numbombs; j++)
            fscanf(fin, "%d%d", &bombs[j].x, &bombs[j].y);
        
        // Output header.
        printf("Test case %d:\n", i);
        
        // Loop through each square on the board in the order specified by the
        // problem.
        for (x=1; x<=n; x++) {
            for (y=1; y<=n; y++) {
                
                // See if this square is adjacent to any of the bombs 
                // or is a bomb. If so, break out of the loop!
                for (j=0; j<numbombs; j++) {
                    if ((abs(bombs[j].x-x) == 0 || abs(bombs[j].x-x) == 1) &&
                        (abs(bombs[j].y-y) == 0 || abs(bombs[j].y-y) == 1))
                        break;
                }
                
                // This means we didn't break, so print out (x,y).
                if (j == numbombs) printf("(%d,%d)\n",x,y);
            }
        }
        
        // Blank line between cases.
        printf("\n");
    }
    
    fclose(fin);
    //system("PAUSE");
    return 0;
}
