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<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
    int d,N;
    cin>>d;
    for(int i=0;i<d;i++){
        int N;
        cin>>N;
        char fie[200][200];
        for(int i=0;i<200;i++){
            for(int j=0;j<200;j++)fie[i][j]=' ';
        }
        for(int j=0;j<N;j++)fie[j][0]='#';
        int x=0,y=0;
        for(int j=0;;j++){
            int p=(N-1)-(j/2*2);
            if(p<=0||(p==1&&j%2==1&&N%2==0))break;
            for(int k=0;k<p;k++){
                y+=dy[j%4],x+=dx[j%4];
                fie[y][x]='#';
            }
        }
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                cout<<fie[j][k];
            }
            puts("");
        }
        if(i!=d-1)puts("");
    }
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

bool range(int n, int x, int y)
{
	return 0 <= x && x < n && 0 <= y && y < n;
}
void rec(vector<vector<char> >& g, int x, int y, int dx, int dy, int c)
{	
	int n = g.size();
	if(c == 4) return;
	
	g[x][y] = '#';

	int nx = x + dx, ny = y + dy;
	if(range(n, nx, ny) && g[nx][ny] != '#' && (range(n, nx + dx, ny + dy) ? g[nx + dx][ny + dy] != '#' : true))
	{
		rec(g, nx, ny, dx, dy, 0);
	}
	else
	{
		if(dx == 0 && dy == -1) 	rec(g, x, y,  1, 0, c + 1);
		else if(dx == 1 && dy == 0)	rec(g, x, y,  0, 1, c + 1);
		else if(dx == 0 && dy == 1)	rec(g, x, y, -1, 0, c + 1);
		else						rec(g, x, y, 0, -1, c + 1);
	}
}

int main()
{
	int d;
	cin >> d;
    
	for(int n; d && cin >> n; d--)
	{
		vector<vector<char> > g(n, vector<char>(n, ' '));
		
		rec(g, 0, n - 1, 0, -1, 0);
		
		if(n % 2 == 0) g[n / 2][n / 2] = ' ';
		
		rep(y, n) rep(x, n) cout << g[x][y] << (x + 1 == n ? "\n" : "");
		
		if(d != 1) cout << endl;
	}
}

C++: #include <iostream>
#include <string.h>

using namespace std;
typedef pair<int, int> P;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
bool field[104][104];

void solve()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i)
	{
		memset(field, 1, sizeof(field));
		int num;
		cin >> num;
		for(int j = 0; j < num + 4; ++j)
		{
			field[0][j] = false;
			field[num + 3][j] = false;
		}
		for(int j = 1; j < num + 4; ++j)
		{
			field[j][0] = false;
			field[j][num + 3] = false;
		}
		P pos;
		pos.first = 2;
		pos.second = num + 1;
		int count = num;
		int step = 0;
		field[pos.second][pos.first] = false;
		while(count)
		{
			while(2 <= pos.first && pos.first < (num + 2) && 2 <= pos.second && pos.second < (num + 2))
			{
				if(field[pos.second + 2 * dy[step]][pos.first + 2 * dx[step]] == false)
				{
					break;
				}
				pos.first += dx[step];
				pos.second += dy[step];
				field[pos.second][pos.first] = false;
			}
			step = (step + 1) % 4;
			count--;
		}
		for(int j = 2; j < num + 2; ++j)
		{
			for(int k = 2; k < num + 2; ++k)
			{
				field[j][k] == true ? cout << ' ' : cout << '#';
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

main(){
  int n;
  char data[100][100];
  int dx[] = {0, 1, 0, -1};
  int dy[] = {-1, 0, 1, 0};
  int t;
  while(cin >> t){
  {
    for(int tc=0;tc<t;tc++){
      cin >> n;
      if(tc != 0) cout << endl;
      if(n == 1){
	cout << "#" << endl;
	f = false;
	continue;
      }
      int y = n-1;
      int x = 0;
      fill(data[0], data[100], ' ');
      data[y][x] = '#';
      int d = 0;
      while(1){
	int ty = y + dy[d];
	int tx = x + dx[d];
	if(ty<0 || ty>=n){ d = (d+1)%4; continue; }
	if(tx<0 || tx>=n){ d = (d+1)%4; continue; }
	if(data[ty][tx] == '#') break;
	int tty = ty + dy[d];
	int ttx = tx + dx[d];
	if((tty>=0 || tty<n) && (ttx>=0 || ttx<n)){
	  if(data[tty][ttx] == '#'){
	    d = (d+1)%4; 
	    continue; 
	  }
	}
	int cnt = 0;
	for(int i=0;i<4;i++){
	  int tty = ty + dy[i];
	  int ttx = tx + dx[i];
	  if(tty<0 || tty>=n) continue;
	  if(ttx<0 || ttx>=n) continue;
	  if(data[tty][ttx] == '#') cnt++;
	}
	if(cnt > 1) break;
	data[ty][tx] = '#';
	y = ty;
	x = tx;
      }
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  cout << data[i][j];
	}
	cout << endl;
      }
    }
  }
  return 0;
}