Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	out := make([][]string, 100)
	for i := range out {
		out[i] = make([]string, 101)
	}
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	scanner.Scan()
	a, _ := strconv.Atoi(scanner.Text())
	for a > 0 {
		a--
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < b; i++ {
			for j := 0; j < b; j++ {
				out[i][j] = " "
			}
			out[i][b] = "0"
		}
		if b == 1 {
			fmt.Println("#")
			if a != 0 {
				fmt.Println()
			}
			continue
		}
		if b == 2 {
			fmt.Println("##")
			if a != 0 {
				fmt.Println()
				continue
			}
		}
		row := b -1
		col := 0
		dir := 0
		l := 0
		out[row][col] = "#"
		for {
			nrow := row+dy[dir%4]
			ncol := col+dx[dir%4]
			if dir%4 == 0 && nrow == 0 || dir%4==3&&ncol==0 || dir%4==2&&nrow==b-1 || dir%4==1&&ncol==b-1 {
				row=nrow
				col=ncol
				out[row][col]="#"
				dir++
				l = 1
			} else if out[nrow+dy[dir%4]][ncol+dx[dir%4]]=="#" {
				if l < 3 {
					break
				}
				dir++
				l = 1
			} else {
				row=nrow
				col=ncol
				out[row][col]="#"
				l++
			}
		}
		for i := 0; i < b; i++ {
			for j := 0; j < b; j++ {
				fmt.Printf("%s", out[i][j])
			}
			fmt.Println()
		}
		if a != 0 {
			fmt.Println()
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

char maze[110][110];
int dx[] = {0,1,0,-1} , dy[] = {-1,0,1,0};
int size;

bool over(int x,int y){
  return x < 0 || size <= x || y < 0 || size <= y;
}
bool space(int x,int y){
  int cnt = 0;
  rep(i,4){
    int nx = x + dx[i], ny = y + dy[i];
    if(maze[ny][nx] == '#')
      cnt ++;
  }
  return cnt > 1;
}
void dfs(int x,int y,int d){
  if(size <= x) 
    dfs(x-1,y,2);
  if(y < 0)
    dfs(x,y+1,1);
  if(size <= y)
    dfs(x,y-1,3);
  if(space(x,y))
    return ;
  if(over(x,y))return;
  maze[y][x] = '#';
  
  int nnx = x + 2 * dx[d] , nny = y + 2 * dy[d];
  if(maze[nny][nnx] == '#')
    d = (d+1)%4;
  dfs(x+dx[d],y+dy[d],d);

}

void solve(int n){
  size = n;
  dfs(0,n-1,0);
  rep(i,n){
    rep(j,n){
      cout<<maze[i][j];
    }
    cout<<endl;
  }
}

int main(void){
  int n,in;
  cin>>n;
  rep(time,n){
    cin>>in;
    rep(i,in)rep(j,in)maze[i][j] = ' ';
    solve(in);
    cout<<endl;
    // if(!time)cout<<endl;
  }
}

C++: #include <cstdio>
#include <cstring>

int d,n;
int fie[101][101];
int xmax[101];
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};

int max(int a,int b){
	if(a>b)return a;
	return b;
}

int main(void){
	scanf("%d",&d);
	for(int data=0;data<d;data++){
		if(data>0)printf("\n");
		scanf("%d",&n);
		memset(fie,0,sizeof(fie));
		memset(xmax,0,sizeof(xmax));
		for(int i=0;i<n;i++){
			fie[0][i]=1;
		}
		int len=0,mlen=n-1,x=0,y=0,dir=1,cnt=0;
		while(mlen>0){
			x+=dx[dir];
			y+=dy[dir];
			xmax[y]=max(xmax[y],x);
			fie[x][y]=1;
			len++;
			if(len==mlen){
				cnt++;
				if(mlen==1)break;
				dir=(dir+1)%4;
				len=0;
			}
			if(cnt==2){
				mlen-=2;
				cnt=0;
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<=xmax[i];j++){
				printf("%c",fie[j][i]==1?'#':' ');
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>

#define EPS	1.0e-10
#define rep(idx, max)	for(int idx = 0, idx##Max = max; idx < idx##Max; idx ++)
#define rrep(idx, min, max)	for(int idx = min, idx##Max = max; idx < idx##Max; idx ++)
#define erep(idx, min, max)	for(int idx = min, idx##Max = max; idx <= idx##Max; idx ++)

#define rev(idx, max)	for(int idx = max - 1; idx >= 0; idx --)
#define MAX_N	128
char g_map[MAX_N][MAX_N];

int main()
{
	static int dx[] = { -1, 0, 1, 0 };
	static int dy[] = { 0, -1, 0, 1 };
	int dir;
	int edgeLen;
	int testCases;

	std::cin >> testCases;
	while (testCases -- > 0)
	{
		int x, y;
		std::cin >> edgeLen;
		::memset(g_map, ' ', sizeof(g_map));

		rep(y, edgeLen)
		{
			g_map[y][edgeLen] = '\0';
		}

		dir = 0;
		// ????????????????????????????????????????????????2????????????
		x = edgeLen + 2 - 1;
		y = edgeLen + 2 - 1;
		for (int n = edgeLen + 2; n >= 2; )
		{
			rep(i, n == 2 ? 1 : 2)
			{
				rep(j, n)
				{
					g_map[y][x] = '#';
					//::printf("(%d, %d)\n", x, y);
					x += dx[dir];
					y += dy[dir];
				}
				x -= dx[dir];
				y -= dy[dir];
				dir = (dir + 1) & 0x03;
			}
			n -= 2;
		}

		rep(y, edgeLen)
		{
			::puts(&g_map[y][0]);
		}
	}

	return(0);
}

C++: #include <stdio.h>

#define N 100

int main(void){
    int dx[] = {0,1,0,-1};
    int dy[] = {-1,0,1,0};
    int map[N+2][N+2];
    int datas,d,dd,n;
    int x,y;
    
    scanf("%d", &datas);
    for (int i=0; i<datas; i++){
        // get size
        scanf("%d", &n);
        // reset map
        for (int xx=0; xx<n+2; xx++){
            for (int yy=0; yy<n+2; yy++){
                if (xx==0 || xx==n+1 || yy==0 || yy==n+1){
                    map[xx][yy]=-1;
                }else {
                    map[xx][yy]=0;
                }
            }
        }
        x=1; y=n; d=0; dd=1;
        // set spiral
        while(1){
            map[x][y]=1;
            if (map[x+dx[d]][y+dy[d]]==0){
                map[x+dx[dd]][y+dy[dd]]=-1;
            } else{
                if (map[x+dx[dd]][y+dy[dd]]==-1){
                    break;
                }else{
                    d = (d+1)%4;
                    dd = (dd+1)%4;
                }
            }
            x += dx[d];
            y += dy[d];
        }
        // output
        for (int yy=1; yy<=n; yy++){
            for (int xx=1; xx<=n; xx++){
                printf(map[xx][yy]==1?"#":" ");
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}

C++: #include <iostream>

#include <string>

using namespace std;

int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};

int main(){

	int d;

	cin >> d;

	for(int t = 0;t < d;t++){

		if(t) cout << endl;

		char s[100][100];

		int n;

		cin >> n;
		
		if(n == 1){
			cout << "#" << endl;
			continue;
			}

		for(int i = 0;i < n;i++){

			for(int j = 0;j < n;j++) s[i][j] = ' ';

		}

		int x = n - 1,y = 0,dir = 0;

		for(int k = 0;k < n;k++){

			bool flag = false;

			while(1){

				int nx = x + dx[dir],ny = y + dy[dir];

			 if(nx < 0 || nx >= n + 1 || ny < 0 || ny >= n + 1 || s[nx][ny] == '#') break;

s[x][y] = '#';

flag = true;

				x = nx;

				y = ny;

			}

if(x)x -= dx[dir];

if(y)y -= dy[dir];

			if(!flag) break;

			dir = (dir + 1) % 4;

		}

for(int i = 0;i < n;i++) {

for(int j = 0;j < n;j++){

cout << s[i][j];

}

cout << endl;}

	}

}