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.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<iostream>
#include<cstring>

using namespace std;

const int MAX = 101;
char data[MAX][MAX];
int n;
int dx[4] = {0,1,0,-1};
int dy[4] = {-1,0,1,0};
 
void print(){
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++)
      cout << data[i][j];
    cout << endl;
  }
}

bool movable(int d, int x, int y){
  return data[y+dy[d]][x+dx[d]] == ' ';
}

void solve(){

  int x = 2,y = n-1;
  int d = 0;

  for(int i = 0; i < n; i++)
    data[0][i] = data[n-1][i] = data[i][0] = data[i][n-1] = '#';

  data[n-1][1] = ' ';

  while(1){
    int num = 0;

    while(1){
      x += dx[d];
      y += dy[d];
      if(movable(d,x,y)){
	num++;
	data[y][x] = '#';
      }else{
	x -= dx[d];
	y -= dy[d];
	break;
      }
    }
    if(num < 2) break;
    d++;
    d%=4;
  }
}

void init(){
  memset(data,' ',sizeof(data));
}

int main(){

  bool line = false;
  int x;
  cin >> x;
  
  while(x--){
    if(line) cout << endl;
    line = true;
    init();
    cin >> n;
    solve();
    print();
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
//#include <map>
#include <set>
#define INF (1000000000)
#define MOD (1000000007)
#define K (2)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;
typedef pair<int, int> PII;


char map[200][200];
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

int main()
{
	int num;
	scanf("%d", &num);
	for (int ca = 0; ca < num; ca++){
		for (int i = 0; i < 200; i++){
			strcpy(map[i], "");
		}
		
		int n;
		scanf("%d", &n);
		
		for (int i = 0; i < n + K + K; i++){
			for (int j = 0; j < n + K + K; j++){
				if (!i || !j || i == n + K + K - 1 || j == n + K + K - 1){
					map[i][j] = '#';
				}
				else {
					map[i][j] = ' ';
				}
			}
		}
		
		int y = n - 1 + K;
		int x = K;
		int d = 0;
		int nodraw = 0;
		while (true){
			int b = (d + 2) % 4;
			int r = (d + 1) % 4;
			if (map[y + dy[b]][x + dx[b]] != '#' || map[y + dy[r]][x + dx[r]] != '#'){
				map[y][x] = '#';
			}
			else {
				break;
			}
						
			if (map[y + dy[d] * 2][x + dx[d] * 2] == '#'){
				d = (d + 1) % 4;
				if (++nodraw == 4){
					break;
				}
			}
			else {
				y += dy[d];
				x += dx[d];
				nodraw = 0;
			}
		}
		
		for (int i = 2; i < n + K; i++){
			printf("%.*s\n", n, &map[i][2]);
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>

using namespace std;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

class Pos
{
public:
	int x, y;
};

void solve()
{
	int d;
	cin >> d;
	bool first = true;
	while(d--)
	{
		if(!first)
		{
			cout << endl;
		}
		first = false;
		int n;
		cin >> n;
		if(n == 1)
		{
			cout << "#" << endl;
			continue;
		}
		else if(n == 2)
		{
			cout << "##" << endl;
			cout << "#" << endl;
			continue;
		}
		vector< vector<char> > field(n, vector<char>(n));
		for(int i = 0; i < n; ++i)
		{
			field[i][0] = '#';
			field[i][n - 1] = '#';
			field[0][i] = '#';
		}
		int direction = 0;
		Pos current;
		current.x = n - 1;
		current.y = n - 1;
		while(true)
		{
			Pos next;
			next.x = current.x + dx[direction];
			next.y = current.y + dy[direction];
			int count = 0;
			while(field[next.y + dy[direction]][next.x + dx[direction]] != '#')
			{
				field[next.y][next.x] = '#';
				current = next;
				next.x = current.x + dx[direction];
				next.y = current.y + dy[direction];
				++count;
			}
			direction = (direction + 1) % 4;
			if(count < 2)
			{
				break;
			}
		}
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cout << field[i][j];
			}
			cout << endl;
		}
	}
}

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

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int d;
    cin >> d;
    int n;
    REP(k,d){
        cin >> n;
        int box[n][n]={};
        for(int i=0;i<n/2+1;i+=2){

            for(int y=i;y<n-i;y++){
                for(int x=i;x<n-i;x++){
                    if(y==i||y==n-i-1||x==i||x==n-i-1)box[y][x]=1;
                }
            }
        }
        for(int i=0;i<n/2;i+=2){
            if(box[n-1-i][i+1]){
                if(box[n-2-i][i+2]==0){
                    if(box[n-3-i][i+2]){
                        swap(box[n-1-i][i+1],box[n-2-i][i+2]);
                    }else{
                        box[n-1-i][i+1]=box[n-2-i][i+2];
                    }
                }else{
                    box[n-1-i][i+1]=0;
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(box[i][j])cout <<"#";
                else cout << " ";
                if(j!=n-1)cout << " ";
            }
            cout << endl;
        }
    }
}

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);
    if(i != d-1)
      cout << endl;
  }
  return 0;
}