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, 100)
	}
	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.Println("##")
			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<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

void solve(char a[105][105], int inp, int d, int y, int x){
    int i;
    for(i = 0; i < inp - 1; i++){
        a[y][x] = '#';
        if(d == 0){
            if(a[y - 2][x] == '#') break;
            y--;
        }else if(d == 1){
            if(a[y][x + 2] == '#') break;
            x++;
        }else if(d == 2){
            if(a[y + 2][x] == '#') break;
            y++;
        }else{
            if(a[y][x - 2] == '#') break;
            x--;
        }
    }
    if(i <= 1) return;
    solve(a, inp, (d + 1) % 4, y, x);

}

int main(){
    int n;
    char a[105][105];
    cin >> n;
    rep(i,n){
        if(i) cout << endl;
        rep(i,105) rep(j,105) a[i][j] = ' ';
        int inp;
        cin >> inp;
        solve(a, inp, 0, 104, 0);
        if(inp == 1) cout << '#' << endl;
        else if(inp == 2) cout << "##" << endl << "# " << endl;
        else{
            for(int i = 104 - inp + 1; i <= 104; i++){
                rep(j,inp){
                    cout << a[i][j];
                }
                cout << endl;
            }
        }
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int d, n;
char field[110][110];

int main(){
	cin >> d;
	while (d--){
		REP(i, 110)REP(j, 110)field[i][j] = ' ';
		cin >> n;
		REP(i, n)field[i][0] = '#';
		int sx = 0, sy = 0;
		int w = n - 1;
		bool f = 0;
		while (w >= 2){
			if (f == 0){
				REP(i, w){
					sx++;
					field[sy][sx] = '#';
				}
				REP(i, w){
					sy++;
					field[sy][sx] = '#';
				}
				w -= 2;
				f = 1;
			}
			else{
				REP(i, w){
					sx--;
					field[sy][sx] = '#';
				}
				REP(i, w){
					sy--;
					field[sy][sx] = '#';
				}
				w -= 2;
				f = 0;
			}
		}
		if (w == 1){
			if (f == 0)field[sy][sx + 1] = '#';
			else field[sy][sx - 1] = '#';
		}
		REP(i, n){
			REP(j, n){
				cout << field[i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
}

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

using namespace std;

int main()
{
	int n, s, t = 0, x, y, m, l;
	char a[110][110];
	
	cin >> l;
	while(l--){
		cin >> n;
		if(t == 1){
			cout << endl;
		} else if(n == 1){
			cout << "#" << endl;
			t = 1;
		}
		fill(&a[0][0], &a[109][109], ' ');
		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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int main(){
	int n;
	cin>>n;
	rep(l,n){
		int m;
		cin>>m;
		// cout<<m<<endl;
		if(m==1){
			cout<<"#\n\n";
			continue;
		}
		if(m==2){
			cout<<"##\n";
			cout<<"# \n\n";
			continue;
		}
		if(m==3){
			/*
			###
			# #
			# #
			*/
			cout<<"###\n";
			cout<<"# #\n";
			cout<<"# #\n";
			cout<<"\n";
			continue;
		}
		vector<vector<char> > vv;
		initvv(vv,m,m);
		rep(i,m){
			rep(j,m) vv[i][j]=' ';
		}
		rep(i,m){
			vv[0][i]='#';
			vv[m-1][i]='#';
			vv[i][m-1]='#';
			vv[i][0]='#';
		}
		vv[m-1][1]=' ';
		int x=m-1,y=2;
		int c=0;
		while(1){
			// cout<<x<<" "<<y<<endl;
			if(vv[x+dx[c]*2][y+dy[c]*2]==' '){
				x+=dx[c];
				y+=dy[c];
				vv[x][y]='#';
			}
			else if(vv[x+2*dx[(c+1)%4]][y+2*dy[(c+1)%4]]==' '&&vv[x+dx[(c+1)%4+dx[(c+2)%4]]][y+dy[(c+1)%4]+dy[(c+2)%4]]==' '){
				c++;
				c%=4;
				x+=dx[c];
				y+=dy[c];
				vv[x][y]='#';
			}
			else{
				break;
			}
		}
		/*
		######
		#    #
		# ## #
		# #  #
		# #  #
		# ####
		*/
		rep(i,m){
			rep(j,m){
				cout<<vv[i][j];
			}
			cout<<endl;
		}
		cout<<endl;
	}
}