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>

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++: //01
#include<iostream>
#include<algorithm>

using namespace std;

int n;
char g[100][100];

bool fr(int y,int x,int py,int px){
  bool f=true;
  for(int i=0;i<4;i++){
    int d[]={0,1,0,-1,0};
    int jy=y+d[i];
    int jx=x+d[i+1];
    f&=min(jx,jy)<0||n<=max(jx,jy)||(px==jx&&py==jy)||g[jy][jx]==' ';
  }
  return f;
}

int main(){
  int d;
  cin>>d;
  while(d--){
    cin>>n;
    fill(g[0],g[100],' ');
    g[0][0]='#';
    int d=0,y=0,x=0;
    int p=0;
    for(;;){
      int dx[]={0,1,0,-1};
      int dy[]={1,0,-1,0};
      int ny=y+dy[d];
      int nx=x+dx[d];
      int jy=ny+dy[d];
      int jx=nx+dx[d];
      if(0<=min(nx,ny)&&max(nx,ny)<n&&fr(ny,nx,y,x)){
	y=ny;
	x=nx;
	g[ny][nx]='#';
	p=0;
      }else{
	p++;
	d=(d+1)%4;
	if(p>=2){
	  break;
	}
      }
    }
    for(int y=n-1;y>=0;y--){
      for(int x=0;x<n;x++){
	cout<<g[y][x];
      }
      cout<<endl;
    }
    if(d){
      cout<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define MAX_N 7500
int n, cnt, cx, cy;
bool x[MAX_N][MAX_N];
bool y[MAX_N][MAX_N];
int main() {
	while (cin >> n) {
		cnt = 0;
		memset(x, true, sizeof(x));
		memset(y, false, sizeof(y));
		for (int i = 10; i < 10 + n; i++) {
			for (int j = 10; j < 10 + n; j++) {
				x[i][j] = false;
			}
		}
		cy = 10 + n;
		cx = 10;
		while (cnt <= MAX_N) {
			while (x[cy - 1][cx] == false && y[cy - 2][cx] == false && y[cy - 1][cx + 1] == false) {
				cy--;
				y[cy][cx] = true;
			}
			while (x[cy][cx + 1] == false && y[cy][cx + 2] == false) {
				cx++;
				y[cy][cx] = true;
			}
			while (x[cy + 1][cx] == false && y[cy + 2][cx] == false && y[cy + 1][cx - 1] == false) {
				cy++;
				y[cy][cx] = true;
			}
			while (x[cy][cx - 1] == false && y[cy][cx - 2] == false) {
				cx--;
				y[cy][cx] = true;
			}
			cnt++;
		}
		for (int i = 10; i < 10 + n; i++) {
			for (int j = 10; j < 10 + n; j++) {
				if (y[i][j] == true) {
					cout << '#';
				}
				else {
					cout << ' ';
				}
			}
			cout << endl;
		}
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int n;
char s[105][105];
int dx[]{ -1,0,1,0 }, dy[]{ 0,1,0,-1 };

void dfs(int idx, int x, int y) {
	if (s[x][y] == '#')return;
	s[x][y] = '#';
	int nx = x + dx[idx], ny = y + dy[idx];
	if (nx < 0 || n <= nx || ny < 0 || n <= ny) {
		idx = (idx + 1) % 4;
		dfs(idx, x + dx[idx], y + dy[idx]);
		return;
	}
	int kx = nx + dx[idx], ky = ny + dy[idx];
	if (!(0 <= kx&&kx < n && 0 <= ky&&ky < n&&s[kx][ky] == '#')) {
		dfs(idx, nx, ny);
		return;
	}
	idx = (idx + 1) % 4;
	nx = x + dx[idx], ny = y + dy[idx];
	kx = nx + dx[idx], ky = ny + dy[idx];
	int jx = nx + dx[(idx + 1) % 4], jy = ny + dy[(idx + 1) % 4];
	if ((!(0 <= kx&&kx < n && 0 <= ky&&ky < n&&s[kx][ky] == '#'))&& (!(0 <= jx&&jx < n && 0 <= jy&&jy < n&&s[jx][jy] == '#'))) {
		dfs(idx, nx, ny);
		return;
	}
}
int main() {
	int d; scanf("%d", &d);
	rep(i, d) {
		scanf("%d", &n);
		if (n == 1) {
			puts("#"); continue;
		}
		rep(j, n)rep(k, n)s[j][k] = ' ';
		dfs(0, n - 1, 0);
		rep(j, n)printf("%s\n", s[j]);
	}
}