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 <iostream>
#include <vector>
using namespace std;

void draw(int width, int x, int y, vector<string>& a) {
    if (width == 1) {
        a[x][y] = '#';
    } else if (width == 2) {
        a[x][y] = a[x+1][y] = a[x][y+1] = '#';
    } else if (width == 3) {
        a[x][y] = a[x][y+1] = a[x][y+2] = '#';
        a[x+1][y] = a[x+1][y+2] = '#';
        a[x+2][y] = a[x+2][y+2] = '#';
    } else if (width == 4) {
        a[x][y] = a[x][y+1] = a[x][y+2] = a[x][y+3] = '#';
        a[x+1][y] = a[x+1][y+3] = '#';
        a[x+2][y] = a[x+2][y+3] = '#';
        a[x+3][y] = a[x+3][y+2] = a[x+3][y+3] = '#';
    } else {
        for (int j = 0; j < width; ++j) {
            a[x][y+j] = '#';
        }
        for (int j = 1; j < width; ++j) {
            a[x+j][y] = '#';
            a[x+j][y+width-1] = '#';
        }
        for (int j = 2; j < width; ++j) {
            a[x+width-1][y+j] = '#';
        }
        a[x+width-2][y+2] = '#';
        draw(width-4, x+2, y+2, a);
    }
}

int main() {
    int N;
    cin >> N;
    for (;N--;) {
        int W;
        cin >> W;
        vector<string> a(W, string(W, ' '));

        draw(W, 0, 0, a);
        for (int j = 0; j < W; ++j) {
            cout << a[j] << endl;
        }
        if (N > 0) {
            cout << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i<n; i++) {
		int a, f;
		cin >> a;
		f = a*a;
		char b[100][100], c[100][100];
		for (int j = 0; j < a; j++) {
			for (int z = 0; z < a; z++) {
				b[j][z] = ' ';
				c[j][z] = ' ';
			}
		}
		int h = (a - 1), w = 0, h2 = -1, w2 = 0;
		b[h][w] = '#';
		c[h][w + 1] = '#';
		c[h][w] = '#';
		f -= 2;
		int k = 0;
		while (f >= 0) {
			if (h + h2 >= a || h + h2 < 0 || w + w2 >= a || w + w2 < 0 || c[h + h2][w+w2] == '#' ) {
				if (h2 == -1) {
					h2 = 0;
					w2 = 1;
				}
				else if (h2 == 1) {
					h2 = 0;
					w2 = -1;
				}
				else if (w2 == -1) {
					w2 = 0;
					h2 = -1;
				}
				else if (w2 == 1) {
					w2 = 0;
					h2 = 1;
				}
			}
			h += h2;
			w += w2;
			if (c[h][w] != '#')
				f--;
			b[h][w] = '#';
			c[h][w] = '#';
			if (h2 == -1) {
				if (c[h][w + 1] != '#')
					f--;
				c[h][w + 1] = '#';
			}
			else if (h2 == 1) {
				if (c[h][w - 1] != '#')
					f--;
				c[h][w - 1] = '#';
			}
			else if (w2 == -1) {
				if (c[h - 1][w] != '#')
					f--;
				c[h - 1][w] = '#';
			}
			else if (w2 == 1) {
				if (c[h + 1][w] != '#')
					f--;
				c[h + 1][w] = '#';
			}
			if (f == 0) {
				k++;
				if (k ==2) {
					f--;
				}
			}
			if (a % 2 == 1 && f == 0)
				break;
		}
		for (int i = 0; i<a; i++) {
			for (int j = 0; j<a; j++) {
				cout << b[i][j];
			}
			cout << endl;
		}
	}
}

C++: #include<iostream>
using namespace std;


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

int main(){
	bool fst=true;
	int n;
	cin>>n;
	while(n--){
		memset(a,' ',sizeof(a));
		int m,y,x,dir;
		cin>>m;
		y=m;x=1;dir=0;
		a[y][x]='#';
		while(1){
			for(int i=0;i<m-1;i++){
				if(a[y+2*dy[dir]][x+2*dx[dir]]=='#')break;
				y+=dy[dir];
				x+=dx[dir];
				a[y][x]='#';
			}
			dir=(dir+1)%4;
			if(a[y+2*dy[dir]][x+2*dx[dir]]=='#')break;
			if(a[y-1][x-1]=='#'||a[y-1][x+1]=='#'||a[y+1][x-1]=='#'||a[y+1][x+1]=='#')break;
		}
		for(int i=1;i<=m;i++){
			for(int j=1;j<=m;j++)cout<<a[i][j];
			cout<<endl;
		}
		if(!fst)cout<<endl;
		fst=false;
	}
	return 0;
}

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 d;
	cin>>d;
	while(d--){
		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("");
		}
	}
}

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

using namespace std;

int N, n;

char str[200][200];

void set_(int x, int y){
	if(x < 0 || y < 0 || x >= n || y >= n){
		return;
	}
	str[y][x] = ' ';
}

bool checker(int x, int y){
	if(x < 0 || y < 0 || x >= n || y >= n){
		return false;
	}
	if(str[y][x] == 'p'){
		return true;
	}
	return false;
}

bool set(int x, int y, int dx, int dy){
	if(x < 0 || y < 0 || x >= n || y >= n){
		return false;
	}
	if(str[y][x] != 'p'){
		return false;
	}
	str[y][x] = '#';
	if(dx != 0){
		if(checker(x - dx, y - 1)){
			set_(x - dx, y - 1);
		}
		if(checker(x - dx, y + 1)){
			set_(x - dx, y + 1);
		}
	}else{
		if(checker(x - 1, y - dy)){
			set_(x - 1, y - dy);
		}
		if(checker(x + 1, y - dy)){
			set_(x + 1, y - dy);
		}
	}
	if(!set(x + dx, y + dy, dx, dy)){
		if(dx > 0){
			dx = 0;
			dy = 1;
		}else if(dx < 0){
			dx = 0;
			dy = -1;
		}else if(dy > 0){
			dx = -1;
			dy = 0;
		}else{
			dx = 1;
			dy = 0;
		}
		set(x + dx, y + dy, dx, dy);
	}
	return true;
}

int main(){
	
	cin >> N;
	
	for(int loop = 0; loop < N; loop++){
		cin >> n;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				str[i][j] = 'p';
			}
		}
		
		set(0, n - 1, 0, -1);
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(str[i][j] == 'p'){
					str[i][j] = ' ';
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				printf("%c", str[i][j]);
			}
			printf("\n");
		}
		printf("\n");
		cout << endl;
	}
	
	return 0;
}