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++: d = gets.to_i
d.times do |i|
    n = gets.to_i
    a = Array.new(n).map { Array.new(n, 0) }
    a.map! {|r| [9] + r + [9]}
    a.unshift [9] * (n + 2)
    a<< [9] * (n + 2)
    y = n
    x = 1
    dy = -1
    dx = 0
    loop do
        a[y][x] = 1
        if a[y + dy][x + dx] == 0
            a[y + dx][x - dy] = 9
            y += dy
            x += dx
        else
            dy, dx = dx, -dy
            if a[y + dy][x + dx] == 0
                a[y - dx][x + dy] = 9
                y += dy
                x += dx
            else
                break
            end
        end
    end
    a[1..-2].each do |r|
        puts r[1..-2].map {|x| x == 1 ? '#' : ' '} * ''
    end
    puts if i < d - 1
end

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <complex>
#include <string>

using namespace std;

#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)

double const pi = acos(-1);
typedef complex<int> P;
char a[128][128];
int n;

void solve(){
    rep(i,n+4){
        rep(j,n+4){
            if(i*j==0 || (n+3-i)*(n+3-j)==0)a[i][j]='#';
            else a[i][j]=' ';
        }
        a[i][n+4]='\0';
    }

    P d(-1,0), p(n+1,2);
    while(1){
        a[p.real()][p.imag()]='#';
        int y=p.real(), x=p.imag();
        if(a[y+2*d.real()][x+2*d.imag()]=='#')d/=P(0,1);
        if(a[y+2*d.real()][x+2*d.imag()]=='#')break;
        p+=d;
        int c=0;
        rep(i,4){
            int ny=(p+d).real(), nx=(p+d).imag();
            if(a[ny][nx]=='#')c++;
            d*=P(0,1);
        }
        if(c>1)break;
    }
}

int main(){
    int d;cin>>d;
    rep(i,d){
        cin>>n;
        solve();
        rep(i,n){
            rep(j,n)cout<<a[i+2][j+2];
            cout<<endl;
        }
        if(i+1!=d)cout<<endl;
    }
}

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

#define rep(i, n)for((i) = 0;(i) < (n);++(i))

char f[100][100];
int dh[4] = {-1, 0, 1, 0};
int dw[4] = {0, 1, 0, -1};
int main(void){
	int d, n, i, j;
	scanf("%d", &d);
	for(int D = 0;D < d;++D){
		scanf("%d", &n);
		rep(i, n)rep(j, n){
			f[i][j] = ' ';
			if(i == 0 || j == 0 || i == n - 1 || j == n - 1)f[i][j] = '#';
		}
		
		int w = 2, h = n - 1, k = 0;
		f[h][w - 1] = ' ';
		if(n > 4)for(int times = 200000;times--;){
			//printf("%d %d\n", h, w);
			f[h][w] = '#';
			if(f[h + dh[k] + dh[k]][w + dw[k] + dw[k]] == '#')k = (k + 1) % 4;
			else if(f[h + dh[k] + dh[(k + 1) % 4]][w + dw[k] + dw[(k + 1) % 4]] == '#')k = (k + 1) % 4;
			else if(f[h + dh[k] + dh[(k + 3) % 4]][w + dw[k] + dw[(k + 3) % 4]] == '#')k = (k + 1) % 4;
			else{ h += dh[k]; w += dw[k]; }
		}

		rep(i, n){
			rep(j, n)printf("%c",f[i][j]);
			puts("");
		}
		if(D < d)puts("");
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<vector<char>> v(n+2, vector<char>(n+2, 'X'));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                v[i+1][j+1] = ' ';
            }
        }
        array<int, 4> dy{-1, 0, 1, 0}, dx{0, 1, 0, -1};
        int y = n, x = 1;

        for (int i = 0, dir = 0, a = 0; i < 2*n*n; ++i) {
            v[y][x] = '#';
            if(v[y+dy[dir]][x+dx[dir]] != ' ') dir = (dir+1)&3;
            else if(v[y+dy[dir]*2][x+dx[dir]*2] == '#') dir = (dir+1)&3;
            else {
                y += dy[dir];
                x += dx[dir];
            }
        }
        if(!(n&1)) v[n/2+1][n/2+1] = ' ';
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cout << v[i+1][j+1];
            }
            puts("");
        }
        if(t) puts("");
    }
    return 0;
}