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>

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++){
        int m;
        cin >> m; m--;
        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;
        }
        cout << endl;
    }
}

C++: #include <stdio.h>
#pragma warning(disable : 4996)
int n, d, x, y, e, f; char c[100][101];
const int dx[4] = { 0, 1, 0, -1 };
const int dy[4] = { -1, 0, 1, 0 };
bool ok() {
	for (int i = 0; i < 4; i++) {
		if (i == (e + 2) % 4) continue;
		int ex = x + dx[i];
		int ey = y + dy[i];
		if (0 <= ex && ex < d && 0 <= ey && ey < d) {
			if (c[ey][ex] == '#') {
				return false;
			}
		}
	}
	return true;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &d);
		x = 0, y = d - 1, e = 0, f = 0;
		for (int j = 0; j < d; j++) {
			for (int k = 0; k < d; k++) {
				c[j][k] = ' ';
			}
			c[j][d] = '\0';
		}
		while (f++ < d * d) {
			c[y][x] = '#';
			x += dx[e % 4];
			y += dy[e % 4];
			if (0 <= x && x < d && 0 <= y && y < d) {
				if (!ok()) {
					x -= dx[e % 4];
					y -= dy[e % 4];
					e++;
				}
			}
			else {
				x -= dx[e % 4];
				y -= dy[e % 4];
				e++;
			}
		}
		if (i) printf("\n");
		for (int j = 0; j < d; j++) printf("%s\n", c[i]);
	}
	return 0;
}

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

using namespace std;

int main(void){
  int d;cin>>d;
  const int POS[][2]={{0,-1},{1,0},{0,1},{-1,0}};
  while(d--){
    int n;cin>>n;
    vector<vector<char> > field(n+2);
    for(int i=0;i<=n+1;++i){
      field[i].reserve(n+2);
      for(int j=0;j<=n+1;++j)field[i][j]=(i==n+1||j==n+1)?1:0;
    }
    int x=0,y=n-1,p=0;
    for(;;){
    	if(x<0||y<0)break;
      int dx=POS[p][0],dy=POS[p][1];
      int px=POS[(p+4+1)%4][0],py=POS[(p+4+1)%4][1],qx=POS[(p+4-1)%4][0],qy=POS[(p+4-1)%4][1];
      field[y][x]=1;
      x+=dx,y+=dy;
      if(y==0&&x==0||(y+2*dy>=0&&x+2*dx>=0&&field[y+2*dy][x+2*dx]==1))p=(p+1)%4;
      if((y+dy+py>=0&&x+dx+px>=0&&field[y+dy+py][x+dx+px]==1)||(y+dy+qy>=0&&x+dx+qx>=0&&field[y+dy+qy][x+dx+qx]==1))
      	break;
    }
    if(n==2)field[1][1]=0;
    for(int i=0;i<n;++i){
      for(int j=0;j<n;++j)cout<<((field[i][j])?'#':' ');
      cout<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>

#include <string>

using namespace std;

??

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

??

int main(){

	int d;

	cin >> d;

	for(int t = 0;t < d;t++){

		if(t) cout << endl;

		char s[100][100];

		int n;

		cin >> n;

		for(int i = 0;i < n;i++){

			for(int j = 0;j < n;j++) s[i][j] = ' ';

		}

		int x = n - 1,y = 0,dir = 0;

		for(int k = 0;k < n;k++){

			bool flag = false;

			while(1){

				int nx = x + dx[dir],ny = y + dy[dir];

			 if(nx < 0 || nx >= n + 1 || ny < 0 || ny >= n + 1 || s[nx][ny] == '#') break;

s[x][y] = '#';

flag = true;

				x = nx;

				y = ny;

			}

if(x)x -= dx[dir];

if(y)y -= dy[dir];

			if(!flag) break;

			dir = (dir + 1) % 4;

		}

for(int i = 0;i < n;i++) {

for(int j = 0;j < n;j++){

cout << s[i][j];

}

cout << endl;}

	}

}

#include <iostream>

#include <string>

using namespace std;

??

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

??

int main(){

	int d;

	cin >> d;

	for(int t = 0;t < d;t++){

		if(t) cout << endl;

		char s[100][100];

		int n;

		cin >> n;

		for(int i = 0;i < n;i++){

			for(int j = 0;j < n;j++) s[i][j] = ' ';

		}

		int x = n - 1,y = 0,dir = 0;

		for(int k = 0;k < n;k++){

			bool flag = false;

			while(1){

				int nx = x + dx[dir],ny = y + dy[dir];

			 if(nx < 0 || nx >= n + 1 || ny < 0 || ny >= n + 1 || s[nx][ny] == '#') break;

s[x][y] = '#';

flag = true;

				x = nx;

				y = ny;

			}

if(x)x -= dx[dir];

if(y)y -= dy[dir];

			if(!flag) break;

			dir = (dir + 1) % 4;

		}

for(int i = 0;i < n;i++) {

for(int j = 0;j < n;j++){

cout << s[i][j];

}

cout << endl;}

	}

}