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>
using namespace std;

void draw(int n){
  int m[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
  int t=0, muki=0, x=n+1, y=2;
  int cn[n+4][n+4];
  for(int i=1; i<n+3; i++)
    for(int j=1; j<n+3; j++)
      cn[i][j]=0;
  for(int i=0; i<n+4; i++){
    cn[i][0]=1;
    cn[i][n+3]=1;
    cn[0][i]=1;
    cn[n+3][i]=1;
  }

  while(t<2){
    if(t==1){
      if(cn[x+m[muki%4][0]+m[(muki+1)%4][0]][y+m[muki%4][1]+m[(muki+1)%4][1]]==1)
	break;
    }
    if(cn[x+2*m[muki%4][0]][y+2*m[muki%4][1]]==1)
      {t++; muki++; cn[x][y]=1;}
    else{
      t = 0;
      cn[x][y]=1;
      x+=m[muki%4][0];
      y+=m[muki%4][1];
    }
  }
  
  for(int i=2; i<n+2; i++){
    for(int j=2; j<n+2; j++){
      if(cn[i][j]==1)
	cout << "#";
      else
	cout << " ";
    }
    cout << endl;
  }

}

int main(){
  int d, n;
  cin >> d;

  for(int i=0; i<d; i++){
    cin >> n;
    draw(n);
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

void draw(int n) {
  const static int dx[4] = {1,0,-1,0};
  const static int dy[4] = {0,1,0,-1};
  char M[100][100];
  fill(M[0], M[100], '#');
  if(n != 1) {
    int x = 1, y = n-1;
    int dir = 3;

    M[y][x] = ' ';
    
    while(1) {
      int t;
      for(t = 0; t < 2; t++) {
	int nx = x + dx[dir];
	int ny = y + dy[dir];
	int x2 = x + dx[dir]*2;
	int y2 = y + dy[dir]*2;
	if(nx >= 0 && nx < n && ny >= 0 && ny < n && M[ny][nx] == '#' &&
	   x2 >= 0 && x2 < n && y2 >= 0 && y2 < n && M[y2][x2] == '#') {
	  M[ny][nx] = ' ';
	  x = nx;
	  y = ny;
	  break;
	}
	dir = (dir+1)%4;
      }
      if(t == 2) break;
    }
  }

  rep(i, n) {
    rep(j, n) {
      cout << M[i][j];
    }
    cout << endl;
  }
}

main() {
  int d;
  cin >> d;
  rep(i, d) {
    int n;
    cin >> n;
    if(i != 0) cout << endl;
    draw(n);
  }
}

C++: #include<cstdio>

using namespace std;

int main()
{
	char sp[103][103];
	bool chk[103][103];
	int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
	int t;	scanf("%d",&t);

	while(t--){
		int n;	scanf("%d",&n);
		for(int i=0;i<=n+1;i++)	for(int j=0;j<=n+1;j++)	chk[i][j]=true;
		for(int i=1;i<=n;i++)	for(int j=1;j<=n;j++)	sp[i][j]=' ',chk[i][j]=false;

		int x=1,y=n,di=1;
		sp[y][x]='#';
		while(1){
			if(chk[y+dy[di]][x+dx[di]]){
				di=(di+3)%4;
				if(chk[y+dy[di]][x+dx[di]])	break;
			}
			else{
				int xl,yl,xr,yr;
				xl=x+dx[(di+1)%4];	yl=y+dy[(di+1)%4];
				xr=x+dx[(di+3)%4];	yr=y+dy[(di+3)%4];
				chk[yl][xl]=chk[yr][xr]=true;

				x+=dx[di];	y+=dy[di];
				sp[y][x]='#';
			}
		}

		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)	putchar(sp[i][j]);
			puts("");
		}
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>

#define EPS	1.0e-10
#define rep(idx, max)	for(int idx = 0, idx##Max = max; idx < idx##Max; idx ++)
#define rrep(idx, min, max)	for(int idx = min, idx##Max = max; idx < idx##Max; idx ++)
#define erep(idx, min, max)	for(int idx = min, idx##Max = max; idx <= idx##Max; idx ++)

#define rev(idx, max)	for(int idx = max - 1; idx >= 0; idx --)
#define MAX_N	128
char g_map[MAX_N][MAX_N];

int main()
{
//	static int dx[] = { 0, 1, 0, -1 };
//	static int dy[] = { -1, 0, 1, 0 };
	static int dx[] = { -1, 0, 1, 0 };
	static int dy[] = { 0, -1, 0, 1 };
	int dir;
	int edgeLen;
	int testCases;

	std::cin >> testCases;
	while (testCases)
	{
		int x, y;
		std::cin >> edgeLen;
		::memset(g_map, ' ', sizeof(g_map));

		rep(y, edgeLen)
		{
			g_map[y][edgeLen] = '\0';
		}

		dir = 0;
		x = edgeLen + 2 - 1;
		y = edgeLen + 2 - 1;
		for (int n = edgeLen + 2; n >= 2; )
		{
			rep(i, n == 2 ? 1 : 2)
			{
				rep(j, n)
				{
					g_map[y][x] = '#';
					//::printf("(%d, %d)\n", x, y);
					x += dx[dir];
					y += dy[dir];
				}
				x -= dx[dir];
				y -= dy[dir];
				dir = (dir + 1) & 0x03;
			}
			n -= 2;
		}

		rep(y, edgeLen)
		{
			::puts(&g_map[y][0]);
			//rep(x, edgeLen)	{	::putchar(g_map[y][x]);	}	::puts("");
		}
		::puts("");
	}

	return(0);
}

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

int n;
char s[500][500];
int dx[]{ -1,0,1,0 }, dy[]{ 0,1,0,-1 };
struct st {
	int a, b, c;
};
int main() {
	int d; scanf("%d", &d);
	rep(i, d) {
		scanf("%d", &n);
		memset(s, 0, sizeof(s));
		rep(j, n)rep(k, n)s[j][k] = ' ';
		queue<st>que;
		s[n - 1][0] = '#';
		que.push({ n - 1, 0,0 });
		while (!que.empty()) {
			st p = que.front(); que.pop();
			int x = p.a, y = p.b, idx = p.c;
			int nx = x + dx[idx], ny = y + dy[idx];
			int kx = nx + dx[idx], ky = ny + dy[idx];
			int jx = nx + dx[(idx + 1) % 4], jy = ny + dy[(idx + 1) % 4];
			if (0 <= nx&&nx < n && 0 <= ny&&ny < n&&s[nx][ny] == ' ') {
				if (!(0 <= kx&&kx < n && 0 <= ky&&ky < n&&s[kx][ky] == '#') && !(0 <= jx&&jx < n && 0 <= jy&&jy < n&&s[jx][jy] == '#')) {
					s[nx][ny] = '#';
					que.push({ nx,ny,idx });
					continue;
				}
			}
			idx = (idx + 1) % 4;
			nx = x + dx[idx]; ny = y + dy[idx];
			kx = nx + dx[idx]; ky = ny + dy[idx];
			jx = nx + dx[(idx + 1) % 4]; jy = ny + dy[(idx + 1) % 4];
			if (0 <= nx&&nx < n && 0 <= ny&&ny < n&&s[nx][ny] == ' ') {
				if (!(0 <= kx&&kx < n && 0 <= ky&&ky < n&&s[kx][ky] == '#') && !(0 <= jx&&jx < n && 0 <= jy&&jy < n&&s[jx][jy] == '#')) {
					s[nx][ny] = '#';
					que.push({ nx,ny,idx });
				}
			}
		}
		rep(j, n)printf("%s\n", s[j]);
	}
}

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};
bool check(int tx,int ty)
{
	if(tx<0||ty<0)return false;
	return buf[tx][ty]=='#';
}
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(check(X+dx[cnt],Y+dy[cnt])&&!check(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;
}