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++){
    if(i!=0){cout<<endl;}
  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>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
// U    0
//L R  3 1
// D    2
int n;
char d[200][200];
int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
void ff(int y,int x,int dir){
	d[y][x]=' ';
	if(d[y+dy[dir]*2][x+dx[dir]*2]=='#'&&y+dy[dir]*2>=0&&y+dy[dir]*2<n&&x+dx[dir]*2>=0&&x+dx[dir]*2<n)
		ff(y+dy[dir],x+dx[dir],dir);
	else
	if(d[y+dy[(dir+1)%4]][x+dx[(dir+1)%4]]!=' '&&d[y+2*dy[(dir+1)%4]][x+2*dx[(dir+1)%4]]=='#'){
		ff(y+dy[(dir+1)%4],x+dx[(dir+1)%4],(dir+1)%4);
	}
}
int main(){
	int s;
	cin>>s;
	while(s--){
		cin>>n;
		rep(i,n)
		rep(j,n)
		d[i][j]='#';
		ff(n-1,1,0);
		rep(i,n){
		rep(j,n)
			cout<<d[i][j];
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

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

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

int main()
{
	int d, i, n, j, k;
	int x, y, dir;
	int turn;
	char s[101][101];
	int dx[4] = {0, 1, 0, -1};
	int dy[4] = {-1, 0, 1, 0};
	int chkx[4] = {1, 1, -1, -1};
	int chky[4] = {-1, 1, 1, -1};
	cin>>d;
	for (i = 0; i < d; i++) {
		cin>>n;
		for (j = 0; j < n; j++)
			for (k = 0; k < n; k++)
				s[k][j] = ' ';
		x = 0; y = n-1; dir = 0;
		turn = 0;
		while (turn<4) {
			s[x][y] = '#';
			if ( isOver(x+dx[dir], y+dy[dir], n) ) {
				dir = (dir+1)%4;
				turn++;
				continue;
			}
			if ( !isOver(x+2*dx[dir], y+2*dy[dir], n) ) {
				if (s[x+2*dx[dir]][y+2*dy[dir]] == '#') {
					dir = (dir+1)%4;
					turn++;
					continue;
				}
			}
			if ( !isOver(x+chkx[dir], y+chky[dir], n) )
				if (s[x+chkx[dir]][y+chky[dir]] == '#') break;
			x += dx[dir];
			y += dy[dir];
			turn = 0;
		}
		if (i) cout<<endl;
		for (j = 0; j < n; j++) {
			for (k = 0; k < n; k++) {
				cout<<s[k][j];
			}
			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[] = { 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 -- > 0)
	{
		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<iostream>
#include<cstring>
using namespace std;

int n;
char c[999][999];
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

bool chk(int y, int x){
  if(y > -1 && x > -1 && y < n+2 && x < n+2 && c[y][x] != ' ') return true;
  return false;
}

void solve(int y, int x, int p){

  int py = y + dy[p], px = x + dx[p];
  int pyy = y + dy[p]*3, pxx = x + dx[p]*3;
  
  if(n == 1){ c[y][x] = '#'; return; }
  if(y < 0 || x < 0 || y == n || x == n || c[y][x] != ' ') return;
  for(int i=0;i<4;i++) if(c[py][px] != ' ' && (i+2)%4 != p) return;
  
  c[y][x] = '#';
  
  if((!py || chk(pyy, pxx)) && !p) p++;
  else if((px == n-1 || chk(pyy, pxx)) && p == 1) p++;
  else if((py == n-1 || chk(pyy, pxx)) && p == 2) p++;
  else if((!px || chk(pyy, pxx)) && p == 3) p = 0;
  
  solve(py, px, p);
}

int main(){

  int l;
  cin >> l;
  while(l--){
    memset(c, ' ', sizeof(c));
    cin >> n;
    solve(n-1,0,0);
    for(int i=0;i<n;i++) c[i][n] = '\0', cout << c[i] << endl;
    if(l) cout << endl;
  }
}