#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int n;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= n-1 && col >= 0 && col <= n-1)return true;
	else{
		return false;
	}
}

int main(){

	int d,row,col,move;
	char current,table[100][101];
	bool FLG,First = true;

	scanf("%d",&d);

	for(int loop=0; loop < d; loop++){
		scanf("%d",&n);


		if(!First)printf("\n");

		for(int i=0; i < n; i++){
			for(int k=0; k < n; k++)table[i][k] = ' ';
		}

		row = n-1,col = 0;
		current = 'U';

		FLG = true;

		while(FLG){
			move = 0;

			switch(current){
			case 'U':

				for(;row >= 0; row--){
					if((rangeCheck(row-1,col) == true && table[row-1][col] == '#')||
					   (rangeCheck(row,col-1) == true && table[row][col-1] == '#')||
					   (rangeCheck(row,col+1) == true && table[row][col+1] == '#'))break;

					table[row][col] = '#';
					move++;
				}
				if(move == 0){
					FLG = false;
				}else{
					row += 1;
					col += 1;
					current = 'R';
				}
				break;
			case 'R':

				for(;col <= n-1; col++){
					if((rangeCheck(row-1,col) == true && table[row-1][col] == '#')||
					   (rangeCheck(row+1,col) == true && table[row+1][col] == '#')||
					   (rangeCheck(row,col+1) == true && table[row][col+1] == '#'))break;

					table[row][col] = '#';
					move++;
				}
				if(move == 0){
					FLG =false;
				}else{
					col -= 1;
					row += 1;
					current = 'D';
				}
				break;
			case 'D':

				for(; row <= n-1; row++){
					if((rangeCheck(row,col-1) == true && table[row][col-1] == '#')||
					   (rangeCheck(row+1,col) == true && table[row+1][col] == '#')||
					   (rangeCheck(row,col+1) == true && table[row][col+1] == '#'))break;

					table[row][col] = '#';
					move++;
				}
				if(move == 0){
					FLG = false;
				}else{
					row -= 1;
					col -= 1;
					current = 'L';
				}
				break;
			case 'L':

				for(; col >= 0; col--){
					if((rangeCheck(row-1,col) == true && table[row-1][col] == '#')||
					   (rangeCheck(row+1,col) == true && table[row+1][col] == '#')||
					   (rangeCheck(row,col-1) == true && table[row][col-1] == '#'))break;

					table[row][col] = '#';
					move++;
				}
				if(move == 0){
					FLG = false;
				}else{
					col += 1;
					row -= 1;
					current = 'U';
				}
				break;
			}
		}

		for(int i=0; i < n; i++){
			for(int k=0; k < n; k++)printf("%c",table[i][k]);
			printf("\n");
		}

		if(First)First = false;

	}


    return 0;
}