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<stdio.h>
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int n;
char t[200][200];
  
int main(){
  int d,D;
  int i,j;
  scanf("%d",&d);
    
  for(D=0;D<d;D++){
    if(D>0)printf("\n");
      
    scanf("%d",&n);
      
    for(i=0;i<=n+3;i++){
      for(j=0;j<=n+3;j++){
        if(i==0||j==0||i==n+3||j==n+3)t[i][j]='#';
        else t[i][j]=' ';
      }
    }
      
    int y=n+1,x=2,dir=0,cnt=1;
    while(1){
      while(1){
        t[y][x]='#';
        if(t[y+dy[dir]*2][x+dx[dir]*2]=='#')break;
        cnt++;
        y+=dy[dir];
        x+=dx[dir];
      }
      if(cnt<=1)break;
      dir=(dir+1)%4;
      cnt=0;
    }
      
    for(i=2;i<2+n;i++){
      for(j=2;j<2+n;j++){
        printf("%c",t[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

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

int main()
{
	int d;

	while( cin >> d ){
		for( int i = 0; i < d; ++i ){
			int n;
			cin >> n;

			int size = n + 4;
			char* map = new char[ size * size ]();
			for( int i = 0; i < size; ++i ){
				map[ i ] = map[ ( size - 1 ) * size + i ] = map[ size * i ] = map[ ( i + 1 ) * size - 1 ] = '#';
			}
			int x = 2, y = n + 1;
			int dir = 0;
			int dirCount = 0;
			int straightCount = 0;
			while( dirCount < 2 ){
				map[ y * size + x ] = '#';
				++straightCount;
				int nx, ny;
				switch( dir ){
					case 0: nx = x; ny = y - 2; break;
					case 1: nx = x + 2; ny = y; break;
					case 2: nx = x; ny = y + 2; break;
					case 3: nx = x - 2; ny = y; break;
				}
				if( map[ ny * size + nx ] == '#' ){
					if( straightCount < 3 ){
						break;
					}
					dir = ( dir + 1 ) % 4;
					++dirCount;
					straightCount = 0;
					continue;
				}else{
					dirCount = 0;
				}
				switch( dir ){
					case 0: y -= 1; break;
					case 1: x += 1; break;
					case 2: y += 1; break;
					case 3: x -= 1; break;
				}
			}

			for( int p = 2; p < size - 2; ++p ){
				for( int q = 2; q < size - 2; ++q ){
					cout << map[ p * size + q ];
				}
				cout << endl;
			}

			delete[] map;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

char f[100][100];
int dw[4] = {0, 1, 0, -1};
int dh[4] = {-1, 0, 1, 0};
signed main(void){
  int i, j;
  int(d);
  for(int testcase = 0;testcase < d;testcase++){
    int(n);
    rep(i, n)rep(j, n)f[i][j] = '.';
    int noww = 0, nowh = n - 1, k = 0;

    bool is = false;
    for(;;){
      //printf("%d %d %d\n", nowh, noww, k);
      f[nowh][noww] = '#';
      if(0 > nowh + dh[k] || nowh + dh[k] >= n || 0 > noww + dw[k] || noww + dw[k] >= n){
        //puts("a");
        if(is)break;
        is = true;
        k = (k + 1) % 4;
        continue;
      }
      if(0 <= nowh + dh[k] * 2 && nowh + dh[k] * 2 < n)
      if(0 <= noww + dw[k] * 2 && noww + dw[k] * 2 < n)
      if(f[nowh + dh[k] + dh[k]][noww + dw[k] + dw[k]] == '#'){
        //puts("b");
        if(is)break;
        is = true;
        k = (k + 1) % 4;
        continue;
      }
      if(0 <= nowh + dh[k] + dh[(k + 1) % 4] && nowh + dh[k] + dh[(k + 1) % 4] < n)
      if(0 <= noww + dw[k] + dw[(k + 1) % 4] && noww + dw[k] + dw[(k + 1) % 4] < n)
      if(f[nowh + dh[k] + dh[(k + 1) % 4]][noww + dw[k] + dw[(k + 1) % 4]] == '#'){
        //puts("c");
        if(is)break;
        is = true;
        k = (k + 1) % 4;
        continue;
      }
      if(0 <= nowh + dh[(k + 3) % 4] && nowh + dh[(k + 3) % 4] < n)
      if(0 <= noww + dw[(k + 3) % 4] && noww + dw[(k + 3) % 4] < n)
      if(f[nowh + dh[(k + 3) % 4]][noww + dw[(k + 3) % 4]] == '#'){
        //puts("d");
        if(is)break;
        is = true;
        k = (k + 1) % 4;
        continue;
      }
      //puts("e");
      is = false;
      nowh += dh[k]; noww += dw[k];
    }

    rep(i, n){
      rep(j, n)printf("%c", f[i][j]);
      puts("");
    }

//*/

//*/ break;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int main(){
	int d,n;
	cin>>d;
	REP(times,d){
		cin>>n;
		char fld[n][n],a,b;
		REP(i,(n+1)/2){
			if(i%2==0){a='#';b=' ';}
			else{a=' ';b='#';}
			REP(j,(n-i*2)){
				fld[i+j][i]=a;
				fld[i][i+j]=a;
				fld[n-1-i][i+j]=a;
				fld[i+j][n-1-i]=a;
			}
			fld[i+1][n-1-i]=b;
		}
		REP(i,n){
			REP(j,n)cout<<fld[j][i];
			cout<<endl;
		}
		cout<<endl;
	}
}