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

char A[100][100];

int main() {
    int D; cin >> D;
    while(D--) {
        int N; cin >> N;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                A[i][j] = ' ';
            }
        }
        int x = 0, y = N;
        const int dx[] = { 0, 1, 0, -1 };
        const int dy[] = { -1, 0, 1, 0 };
        int dir = 0;
        for(int i = 0; i < N; i++) {
            int k;
            if(i == 0) k = N;
            else k = N + 1 - (i + 1) / 2 * 2;

            for(int j = 0; j < k; j++) {
                x += dx[dir]; y += dy[dir];
                A[y][x] = '#';
            }
            (dir += 1) %= 4;
        }
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                cout << A[i][j];
            }
            cout << endl;
        }
        if(D != 0) 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(;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;
		if(n != 2)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 >= 0)puts("");
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long d,n,i,j,k,p,q,r;
string s[100];
cin>>d;
for(k=0;k<d;k++){
cin>>n;
for(i=0;i<n;i++){
s[i].erase();
s[i].resize(n,' ');
}
for(i=n-1;i>=0; i--)s[i][0]='#';
for(j=0;j<n/2;j+=2){
for(i=j;    i<n-j;  i++)s[j]    [i]    ='#';
if(2*j>=n-2)break;
for(i=j;    i<n-j;  i++)s[i]    [n-1-j]='#';
for(i=n-1-j;i>=j+2; i--)s[n-1-j][i]    ='#';
if(2*j>=n-4)break;
for(i=n-1-j;i>=j+2; i--)s[i]    [j+2]  ='#';
}
for(i=0;i<n;i++)cout<<s[i]<<endl;
}
return 0;
}

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

using namespace std;

int main(int argc, char **argv)
{
	int n, s, t = 0, x, y, m, l;
	char a[104][104];
	cin >> l;
	
	while(l--){
		cin >> n;
		if(t == 1){
			cout << endl;
		} else if(n == 1){
			cout << "#" << endl;
			t = 1;
		}
		fill(&a[0][0], &a[n+4][n+4], ' ');
		s = 2;
		t = n+1;
		m = n;
		x = 1;
		y = -1;
		while(m--){
			while(t <= n+1 && t >= 2){
				a[t][s] = '#';
				if(y < 0){
					if(a[t-2][s] == '#'){
						t += y;
						break;
					}
				} else {
					if(a[t+2][s] == '#'){
						t += y;
						break;
					}
				}
				t += y;
			}
			if(m-- == 0){
				break;
			}
			t -= y;
			y = -y;
			while(s <= n+1 && s >= 2){
				a[t][s] = '#';
				if(x < 0){
					if(a[t][s-2] == '#'){
						s += x;
						break;
					}
				} else {
					if(a[t][s+2] == '#'){
						s += x;
						break;
					}
				}
				s += x;
			}
			s -= x;
			x = -x;
		}
		n++;
		for(int i = 2; i <= n; i++){
			for(int j = 2; j <= n; j++){
				cout << a[i][j];
			}
			cout << endl;
		}
		t = 1;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

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

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    bool field[110][110];
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        if(p != 0) cout << endl;
        int m;
        cin >> m; m--;
        if(m == 0){cout << "#" << endl; continue;}
        else if(m == 1){cout << "##" << endl; cout << "#" << endl; continue;}
        rep(i, 110)rep(j, 110)field[i][j] = false;
        int x = 0, y = 0, d = 0;
        while(true){
            if(field[x+dx[d]][y+dy[d]]) break;
            int count = 0;
            for(int i=0; i< m && !field[x+dx[d]*2][y+dy[d]*2]; i++){
                count++;
                field[x][y]= true;
                x += dx[d]; y += dy[d];
                field[x][y] = true;
            }
            if(count == 1) break;
            d = (d+1)%4;
        }

        for(int i=m; 0 <= i; i--){
            for(int j=0; j <= m; j++){
                cout << (field[i][j] ? "#" : " ");
            }
            cout << endl;
        }
    }
}

C++: 
int n;
char G[100][100]; // grid
static int di[4] = {-1, 0, 1, 0};
static int dj[4] = {0, 1, 0, -1};

int main(){
    int dir, width, i, j, a, w;
    int tcase; scanf("%d", &tcase);
    for ( int t = 0; t < tcase; t++ ){
      if ( t ) printf("\n");
      scanf("%d", &n);
      
      for ( i = 0; i < n; i++ )
        for ( j = 0; j < n; j++ ) G[i][j] = ' ';
      
      width = n - 1;
      i = width; j = dir = 0;
      
      for ( a = 1; a <= (n + n % 2); a++, dir = (dir + 1) % 4 ){
        for ( w = 0; w <= width; w++ ) G[i+di[dir]*w][j+dj[dir]*w] = '#';
        i += di[dir] * width;
        j += dj[dir] * width;
        if ( a % 2 == 1 && a >= 3 ) width -= 2;
      }
      
      for ( i = 0; i < n; i++ ){
        for ( j = 0; j < n; j++ ) printf("%c", G[i][j]);
        printf("\n");
      }
    }
}