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>
using namespace std;

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

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

bool inRange(int x, int a, int b) {
	return a<=x && x<=b;
}

void drawSpiral(int n) {
	char mat[N][N];
	rep(i, n) rep(j, n) mat[i][j] = ' ';
	int x = 0, y = n-1, dir = 1, s = 0, mv = n;
	mat[y][x] = '#';
	while(1) {
		for(int i=0; i<mv-1; ++i) {
			x += dx[dir]; y += dy[dir];
			mat[y][x] = '#';
		}
		if(mv<=2 && s>0) break;
		if(s>0 && s%2==0) {
			mv -= 2;
			if(mv<=1) break;
		}
		dir = (dir + 1) % 4;
		++s;
	}
	rep(i, n) {
		rep(j, n) cout << mat[i][j];
		cout << endl;
	}
}

int main() {
	int d, n, count = 0;
	cin >> d;
	while(d--) {
		if(count++>0) cout << endl;
		cin >> n;
		drawSpiral(n);
	}
	return 0;
}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(const _Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,const _Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

const int dir[][2] = {{1,0},{0,1},{-1,0},{0,-1}};

void solve(int m){
    string s;
    REP(i,m) s += " ";
    vector<string> v(m, s);

    int x = 0, y = m-1, d = 3, w = m, h = m, c = 0;
    v[y][x] = '#';
    while(1){
        int mx = x + dir[d][0];
        int my = y + dir[d][1];
        if(mx < 0 || my < 0 || mx >= w || my >= h){
            d = (d+1)%4;
            if(++c >= 2) break;
            continue;
        }
        bool f = true;
        REP(i,4){
            int mx2 = mx + dir[i][0];
            int my2 = my + dir[i][1];
            if(mx2 < 0 || my2 < 0 || mx2 >= w || my2 >= h) continue;
            if(x == mx2 && y == my2) continue;
            if(v[my2][mx2] == '#'){
                f = false; break;
            }
        }
        if(!f){
            d = (d+1)%4;
            if(++c >= 2) break;
            continue;
        }
        c = 0;
        x += dir[d][0], y += dir[d][1];
        v[y][x] = '#';
        //prfep(v);
    }
    FOREACH(it,v) cout << *it << endl;
}

int main(){
    int n, m;
    cin >> n;
    bool f = false;
    while(cin >> m){
        if(f) cout << endl;
        solve(m);
        f = true;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
	char da[102][102];
	int d,n,i,j,x,y,c,f=0,dx,dy,dm;
	cin >> d; 
	for (;d>0;d--) {
		cin >> n;
		for (i=0;i<n+1;i++) for (j=0;j<n+1;j++) da[i][j]=' ';
		for (i=0;i<n+2;i++) {da[i][n+1]='#'; da[n+1][i]='#';}
		dx=0; dy=-1; x=0; y=n-1; c=0;
		while(true) {
			da[y][x]='#';
			if (da[y+dy*2][x+dx*2]=='#' || y+dy==-1) {
				c++; dm=dx; dx=-dy; dy=dm;
				if (c==n) break;
			}
			x+=dx; y+=dy;
		}
		if (f==1) cout << endl; else f=1; 
		for (i=0;i<n;i++) {
			for (j=0;j<n;j++) cout << da[i][j];
			cout << endl;
		}
	}
	return 0;
}

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(x,d){
        cin>>n;
        solve();
        rep(i,n){
            rep(j,n)cout<<a[i+2][j+2];
            cout<<endl;
        }
        if(x+1!=d)cout<<endl;
    }
}