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
		len := 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++
				len = 1
			} else if out[nrow+dy[dir%4]][ncol+dx[dir%4]]=="#" {
				if len < 3 {
					break
				}
				dir++
				len = 1
			} else {
				row=nrow
				col=ncol
				out[row][col]="#"
				len++
			}
		}
		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>
#include<iostream>
using namespace std;





int main(){
  int time;
  cin>>time;
  for(int i=0;i<time;i++){
  char t='u';
  int n;
  cin>>n;
  char a[1000][1000]={};
  fill(&a[0][0],&a[999][1000],' ');
  a[n-1][0]='#';
  pair<int,int> w=make_pair(n-1,0);
  while(1){
    //cout<<t<<" "<<w.first<<" "<<w.second<<endl;
    if(t=='u'){
      if(a[w.first-1][w.second]=='#' || a[w.first-1][w.second+1]=='#'){break;}
      if(w.first==0 || a[w.first-2][w.second]=='#'){t='r'; continue;}
      //w=make_pair(w.first+1,w.second);
      w.first--;
      a[w.first][w.second]='#';
    }
    if(t=='r'){
      if(a[w.first][w.second+1]=='#' || a[w.first+1][w.second+1]=='#'){break;}
      if(w.second==n-1 || a[w.first][w.second+2]=='#'){t='d';  continue;}
      //w=make_pair(w.first,w.second+1);
      w.second++;
      a[w.first][w.second]='#';
    }
    if(t=='d'){
      if(a[w.first+1][w.second]=='#' || a[w.first+1][w.second-1]=='#'){break;}
      if(w.first==n-1 || a[w.first+2][w.second]=='#'){t='l';  continue;}
      //w=make_pair(w.first-1,w.second);
      w.first++;
      a[w.first][w.second]='#';
    }
    if(t=='l'){
      if(a[w.first][w.second-1]=='#' || a[w.first+1][w.second-1]=='#'){break;}
      if(w.second==0 || a[w.first][w.second-2]=='#'){t='u'; continue;}
      //w=make_pair(w.first,w.second-1);
      w.second--;
      a[w.first][w.second]='#';
    }
  }
  for(int i=0;i<n;i++){
    for(int t=0;t<n;t++){
      cout<<a[i][t];
    }
    cout<<endl;
  }
  }
  

  
  return 0;
}

C++: #include <iostream>
using namespace std;

int main(void){
	int i,j,m,n,d,walk;
	int di[]={-1,0,1,0};
	int dj[]={0,1,0,-1};
	char rst[104][104];

	cin>>m;
	while(m--){
		cin>>n;

		for(i=0;i<n+4;i++){
			for(j=0;j<n+4;j++){
				if(i==0 || i==n+3 || j==0 || j==n+3) rst[i][j] = '#';
				else rst[i][j] = ' ';
			}
		}

		i = n + 1;
		j = 2;
		d = 0;

		while(1){
			for(walk=0;rst[i+2*di[d]][j+2*dj[d]] != '#';walk++){
				rst[i][j] = '#';
				i += di[d];
				j += dj[d];
			}

			rst[i][j] = '#';
			d = (d+1) % 4;
			if(walk <= 1) break;
		}

		if(n==2) rst[2][3]='#';
		for(i=2;i<n+2;i++){
			for(j=2;j<n+2;j++) cout<<rst[i][j];
			cout<<endl;
		}
		if(m) cout<<endl;
	}

	return 0;
}

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 ds;
  cin>>ds;
  while(ds--){
    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(ds){
      cout<<endl;
    }
  }
  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[] = { -1, 0, 1, 0 };
	static int dy[] = { 0, -1, 0, 1 };
	int dir;
	int edgeLen;
	int testCases;

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

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

		dir = 0;
		// ????????????????????????????????????????????????2????????????
		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]);
		}
		if (testCases != 0) { ::puts(""); }
	}

	return(0);
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,(n))
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int n;
vector<string> s;

bool outOfRange(int y, int x){
	if(y < 0 || y >= n || x < 0 || x >= n){
		return true;
	}
	return false;
}

bool check(int ny, int nx, int dir){
	if(outOfRange(ny, nx)) return true;
	for(int i = 0; i < 4; i++){
		if(i == (dir+2)%4) continue;
		int nny = ny + dy[i], nnx = nx + dx[i];
		if((!outOfRange(nny, nnx)) && s[nny][nnx] == '#'){
			return true;
		}
	}
	return false;
}

int main(){
	int d;
	cin>>d;
	for(int i = 0; i < d; i++){
		if(i!=0) printf("\n");
		cin>>n;
		s = vector<string>(n,string(n, ' '));
		pii pos = pii(n-1, 0);
		int dir = 0;
		while(1){
			if(s[pos.fi][pos.se]=='#') break;
			s[pos.fi][pos.se] = '#';
			int ny = pos.fi+dy[dir], nx = pos.se+dx[dir];
			int cnt = 4;
			while(check(ny, nx, dir) &&(--cnt)){
				dir++;
				dir%=4;
				ny = pos.fi+dy[dir]; nx = pos.se+dx[dir];

			}
			if(cnt == 0) break;
			pos=pii(ny ,nx);
		}
		rep(i, n){
			cout<<s[i]<<endl;
		}
	}
}