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.Printf("##\n# \n")
			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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int sp[101][101];

main(){
	int e;
	cin>>e;
	while(e--){
		int n;
		cin>>n;
		if(n==1){
			cout<<"#"<<endl;
			continue;
		}
		memset(sp,0,sizeof(sp));
		
		int y=n-1,x=0,d=0;
		int c=0;
		while(true){
			
			
			if(d==0){
				if(sp[y-1][x+1]==1)break;
				int cy=y;
				while(cy>=1){
					if(cy>=2 && sp[cy-2][x]==1)break;
					--cy;
				}
				if(y==cy)break;
				d=(d+1)%4;
				for(;cy<=y;y--)sp[y][x]=1;
				++y;
				continue;
			}
			
			if(d==1){
				if(sp[y+1][x+1]==1)break;
				int cx=x;
				while(cx<=n-2){
					if(cx<=n-3 && sp[y][cx+2]==1)break;
					++cx;
				}
				if(x==cx)break;
				d=(d+1)%4;
				for(;cx>=x;x++)sp[y][x]=1;
				--x;
				continue;
			}
			
			if(d==2){
				if(sp[y+1][x-1]==1)break;
				int cy=y;;
				while(cy<=n-2 && !(cy<=n-3 && sp[cy+2][x]==1))++cy;
				if(cy==y)break;
				d=(d+1)%4;
				for(;cy>=y;y++)sp[y][x]=1;
				--y;
				continue;
			}
			
			if(d==3){
				if(sp[y-1][x-1]==1)break;
				int cx=x;
				while(cx>=1 && !(cx>=2 && sp[y][cx-2]==1))--cx;
				if(x==cx)break;
				d=(d+1)%4;
				for(;cx<=x;x--)sp[y][x]=1;
				++x;
				continue;
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(sp[i][j])printf("#");
				else printf(" ");
			}
			puts("");
		}
		if(e!=0)puts("");
	}
}

C++: #include <iostream>
using namespace std;
int t,u,r,l;

char mark[100][100];
bool flag = 0;
int n;
/*
0:ツ湘」
1:ツ右
2:ツ可コ
3:ツ債カ
*/
void saiki(int x,int y,int turn){
	if(flag){
		if(n%2==0)mark[x][y]='#';
		return;
	}
	mark[x][y]='#';
	if( turn == 0 && y==t ){
		l+=2;
		if(x+1>=r){flag=1;}
		saiki(x+1,y,(turn+1)%4);
	}else if(turn == 2 && y==u ){
		r-=2;
		if(x-1<=l){flag=1;}
		saiki(x-1,y,(turn+1)%4);
	}else if(turn == 3 && x == l){
		u-=2;
		if(y-1<=t){flag=1;}
		saiki(x,y-1,(turn+1)%4);
	}else if(turn == 1 && x == r){
		t+=2;
		if(y+1>=u){flag=1;}
		saiki(x,y+1,(turn+1)%4);
	}else {
		if(turn == 0)saiki(x,y-1,turn);
		else if(turn == 1)saiki(x+1,y,turn);
		else if(turn == 2)saiki(x,y+1,turn);
		else if(turn == 3)saiki(x-1,y,turn);
	}
}

int main(){
	while(cin >> n){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				mark[j][i]=' ';
		}
		flag = 0;
		l = t = 0;
		r = u = n-1;
		saiki(0,n-1,0);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				cout << mark[j][i];
			cout << endl;
		}
		cout << endl;
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>

/*
 
#####
#   #
# # #
# # #
# ###

######
#    #
# ## #
# #  #
# #  #
# ####
 
*/
using namespace std;



void f(char guruguru[100][100], int l, int d, int x, int y){
    
    if(l<=0)return;
    
    if(d==0){//右下
        for(int i=0; i<l; i++){
            guruguru[y][x+i]='#';
        }
        x=x+(l-1);
        
        if(l==2)return;
        
        for(int i=0; i<l; i++){
            guruguru[y+i][x]='#';
        }
        y=y+(l-1);
        l=l-2;
        d=1;
        f(guruguru,l,d,x,y);
    }
    
    if(d==1){//左上
        
        
        for(int i=0; i<l; i++){
            guruguru[y][x-i]='#';
        }
        x=x-(l-1);
        
        if(l<=2)return;
        
        for(int i=0; i<l; i++){
            guruguru[y-i][x]='#';
        }
        y=y-(l-1);

        l=l-2;
        d=0;
        f(guruguru,l,d,x,y);
    }

}

void f0(char guruguru[100][100], int l, int d, int x, int y){
    for(int i=0; i<l; i++){
        guruguru[i][0]='#';
    }
    
    f(guruguru,l,0,0,0);
}


int main(){
    char guruguru_0[100][100];
    char guruguru_1[100][100];
    char guruguru_2[100][100];
    char guruguru_3[100][100];
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            guruguru_0[i][j]=' ';
            guruguru_1[i][j]=' ';
            guruguru_2[i][j]=' ';
            guruguru_3[i][j]=' ';
        }
    }
    
    f0(guruguru_0, 100, 0, 0, 0);
    f0(guruguru_3, 99, 0, 0, 0);
    f0(guruguru_2, 98, 0, 0, 0);
    f0(guruguru_1, 97, 0, 0, 0);
    
    int n;
    cin>>n;
    for(int roop=0; roop<n; roop++){
        int l;
        cin>>l;
        if(l%4==0){
            int x=50-l/2;
            int y=50-l/2;
            for(int i=y; i<y+l; i++){
                for(int j=x; j<x+l; j++){
                    cout<<guruguru_0[i][j];
                }
                cout<<endl;
            }
            cout<<endl;
        }else if(l%4==1){
            int x=50-l/2-2;
            int y=50-l/2-2;
            for(int i=y; i<y+l; i++){
                for(int j=x; j<x+l; j++){
                    cout<<guruguru_1[i][j];
                }
                cout<<endl;
            }
            cout<<endl;
        } else if(l%4==2){
            int x=50-l/2-1;
            int y=50-l/2-1;
            for(int i=y; i<y+l; i++){
                for(int j=x; j<x+l; j++){
                    cout<<guruguru_2[i][j];
                }
                cout<<endl;
            }
            cout<<endl;
        }else if(l%4==3){
            int x=50-l/2-1;
            int y=50-l/2-1;
            for(int i=y; i<y+l; i++){
                for(int j=x; j<x+l; j++){
                    cout<<guruguru_3[i][j];
                }
                cout<<endl;
            }
            cout<<endl;
        }
    }
}

 /*
int main(){

    int n;
    cin>>n;
    for(int roop=0; roop<n; roop++){
        int l;
        cin>>l;
        char guruguru[100][100];
        //memcpy(guruguru,init,sizeof(init));
        for(int i=0; i<l; i++){
            for(int j=0; j<l; j++){
                guruguru[i][j]=' ';
            }
        }
        
        f0(guruguru,l,0,0,0);
        
        for(int i=0; i<l; i++){
            for(int j=0; j<l; j++){
                cout<<guruguru[i][j];
            }
            cout<<endl;
        }
        cout<<endl;
    }
}

*/