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 <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int h, w;

bool can(int y, int x){
	return (0 <= y && y < h && 0 <= x && x < w);
}

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

signed main() {
	int t, n;
	cin >> t;
	rep(k, 0, t){
		int a[110][110]={};
		cin >> n;
		h = w = n;
		vi d;
		int tmp = n;
		d.push_back(tmp);
		while(1){
			if(tmp <= 2){
				d.push_back(tmp);
				break;
			}
			rep(i,0,2) d.push_back(tmp);
			tmp -= 2;
		}
		int y = n - 1, x = 0;
		a[y][x] = 1;
		rep(i, 0, d.size()){
			int dir = i % 4;
			rep(j, 0, d[i] - 1){
				y += dy[dir];
				x += dx[dir];
				a[y][x] = 1;
			}
		}
		rep(i, 0, n){
			rep(j, 0, n){
				cout << (a[i][j] ? '#':' ') ;
			}
			cout << endl;
		}
	}
}

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){
		if(l) cout<<endl;
		int m;
		cin>>m;
		// cout<<m<<endl;
		if(m==1){
			cout<<"#\n";
			continue;
		}
		if(m==2){
			cout<<"##\n";
			cout<<"# \n";
			continue;
		}
		if(m==3){
			/*
			###
			# #
			# #
			*/
			cout<<"###\n";
			cout<<"# #\n";
			cout<<"# #\n";
			// cout<<"\n";
			continue;
		}
		if(m==4){
			cout<<"####\n";
			cout<<"#  #\n";
			cout<<"#  #\n";
			cout<<"# ##\n";
			// cout<<endl;
			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;
	}
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int n;
int fie[110][110]={};
int d[]={-1,0,1,0,-1};


bool turn(int dir,int y,int x){
    int tmpy=y+d[dir];
    int tmpx=x+d[dir+1];
//    cout<<endl;
//    dump(dir);dump(y);dump(x);dump(tmpy);dump(tmpx);
    
    if(fie[y][x]==1 || tmpy<0 || tmpy>=n || tmpx<0 || tmpx>=n || fie[ tmpy+d[dir] ][ tmpx+d[dir+1] ]==1 || fie[ tmpy+d[dir+1] ][ tmpx+d[(dir+1)%4+1] ]==1 )return true;
    else return false;
}


int main() {
    
    int aa;
    cin>>aa;
    rep(i,aa){
        if(i!=0)cout<<endl;
        rep(a,110) rep(b,110) fie[a][b]=0;
        cin>>n;
        
        int dir=0;
        int y=n-1,x=0;
        
        int c=0;
        while(1){
            if( turn(dir,y,x) ){
                c++;
                dir++;
                dir%=4;
            }
            else{
                c=0;
                fie[y][x]=1;
                y+=d[dir];
                x+=d[dir+1];
            }
            if(c==4){
                fie[y][x]=1;
                break;

            }
        }
        
        rep(i,n){
            rep(j,n){
                if(fie[i][j]==1)cout<<"#";
                else cout<<" ";
            }
            cout<<endl;
        }
    }
    
    return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
char buf[150][150];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
void solve(int x)
{
	memset(buf,' ',sizeof(buf));
	for(int i=1;i<=x;i++)
	{
		for(int j=1;j<=x;j++)
		{
			buf[i][j]='#';
		}
	}
	int X=x,Y=2;
	int cnt=0;
	for(int p=0;p<=10000;p++)
	{
		if(x%4==1&&X==(x+3)/2&&Y==(x+1)/2)break;
		if(x%4==3&&X==(x+1)/2&&Y==(x+3)/2)break;
		buf[X][Y]=' ';
		X+=dx[cnt];Y+=dy[cnt];
		if(buf[X+dx[cnt]][Y+dy[cnt]]=='#'&&buf[X+dx[cnt]*2][Y+dy[cnt]*2]!='#')
		{
			cnt++;
			cnt%=4;
		}
	}
	for(int i=1;i<=x;i++)
	{
		for(int j=1;j<=x;j++)
		{
			cout << buf[i][j];
		}
		cout << endl;
	}
	return;
}
int main()
{
	int q;
	cin >> q;
	for(int i=0;i<q;i++)
	{
		int k;
		cin >> k;
		solve(k);
	}
	return 0;
}