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 <string>
#include <vector>
#include <cstring>

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int a[101][101];
	int dx[4] = {0,1,0,-1};
	int dy[4] = {-1,0,1,0};
	
	rep(i,n)
	{
		int r;
		cin >> r;
		int r2 = r;

		memset(a,0,sizeof(a));

		if(r == 1) cout << "#" << endl;
		else if(r == 2)
		{
			cout << "##" << endl;
			cout << "##" << endl;
		}
		else
		{
			int y = r-1;
			int x = 0;
			a[y][x] = 1;

			int dir = 0;

			rep(j,r-1)
			{
				y += dy[dir%4];
				x += dx[dir%4];
				a[y][x] = 1;
			}

			dir++;
			r--;
			
			if(r%2 == 1)
			{
				while(true)
				{
					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;

					if(r == 1) break;

					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;
					r -= 2;
				}
			}
			else
			{
				while(true)
				{
					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;

					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}

					if(r == 2 ) break;

					dir++;
					r -= 2;
				}
			}

			rep(j,r2)
			{
				rep(k,r2)
				{
					if(a[j][k] == 1) cout << "#";
					else cout << " ";
				}
				cout << endl;
			}
		}	
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for (iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};

int main() {
  int t;
  cin >> t;
  bool ck=false;
  while(t--) {
    if(ck) cout << endl;
    ck=true;
    int n;
    cin >> n;
    string s[n][n];
    bool d[n][n];
    rep(i,n) {
      rep(j,n) {
	if(i==0 || j==0 || j==n-1) s[i][j]='#';
	else s[i][j]=' ';
	if(i==n-1 && j==n-1 && n!=1) s[i][j]=' ';
	d[i][j]=false;
	if(i==1 && j>=1 || j==1 && i>=1 || j==n-2 && i>=1 && i<n-1) d[i][j]=true;
      }
    }
    if(n<=2) {
      rep(i,n) {
	rep(j,n) cout << s[i][j];
	cout << endl;
      }
      continue;
    }
    int nx=n-1,ny=n-1,k=3,kk=0;
    while(1) {
      s[nx][ny]='#';
      if(d[nx+dx[k]][ny+dy[k]]) {
	k=(k+1)%4;
	kk=(kk+1)%4;
	if(d[nx+dx[k]][ny+dy[k]]) break;
      }
      d[nx+dx[kk]][ny+dy[kk]]=true;
      nx+=dx[k];
      ny+=dy[k];
    }
    rep(i,n) {
      rep(j,n) cout << s[i][j];
      cout << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
char t[100][100];
int n,a,x,y,d,ny,nx,flg,cnt;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};

void rec(int y,int x,int d){

  
  /*
    for(int i=0;i<a;i++){
      for(int j=0;j<a;j++){
	cout<<t[i][j];
      }
      cout<<endl;
    }

    cout<<y<<' '<<x<<' '<<d<<endl;*/
  cnt=0;
  for(int i=0;i<a;i++){
    t[y][x]='#';cnt++;
    ny=y+dy[d]*2;
    nx=x+dx[d]*2;
    if(t[ny][nx]=='#'){
      break;
    }
    y=y+dy[d];
    x=x+dx[d];
  }
  if(cnt>=3)rec(y,x,(d+1)%4);
}

int main(){
  cin>>n;
  while(n--){
    cin>>a;
    if(a==1){
      cout<<'#'<<endl;
          if(n>=1)cout<<endl;
      continue;
    }else if(a==2){
      cout<<"##"<<endl;
      cout<<"# "<<endl;
    if(n>=1)cout<<endl;
      continue;
    }else if(a==4){
      cout<<"####"<<endl;
      cout<<"#  #"<<endl;
      cout<<"#  #"<<endl;
      cout<<"# ##"<<endl;
    if(n>=1)cout<<endl;
      continue;
    }

    for(int i=0;i<100;i++)
      for(int j=0;j<100;j++)
	t[i][j]=' ';
    
    t[a-1][0]=' ';
    x=0;y=a-1;
    
    for(int i=0;i<a;i++){
      t[a-1][i]=t[i][a-1]='#';
      t[0][i]=t[i][0]='#';
    }
    t[a-1][1]=' ';
    
    rec(a-1,2,0);
    



    for(int i=0;i<a;i++){
      for(int j=0;j<a;j++){
	cout<<t[i][j];
      }
      cout<<endl;
    }
    if(n>=1)cout<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int d;
    cin >> d;
    int n;
    REP(k,d){
        cin >> n;
        int box[n][n]={};
        for(int i=0;i<n/2+1;i+=2){

            for(int y=i;y<n-i;y++){
                for(int x=i;x<n-i;x++){
                    if(y==i||y==n-i-1||x==i||x==n-i-1)box[y][x]=1;
                }
            }
        }
        for(int i=0;i<n/2;i+=2){
            if(box[n-1-i][i+1]){
                if(box[n-2-i][i+2]==0){
                    if(box[n-3-i][i+2]){
                        swap(box[n-1-i][i+1],box[n-2-i][i+2]);
                    }else{
                        box[n-1-i][i+1]=box[n-2-i][i+2];
                    }
                }else{
                    box[n-1-i][i+1]=0;
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(box[i][j])cout <<"#";
                else cout << " ";
            }
            cout << endl;
        }
    }
}