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>
using namespace std;
int t,u,r,l;

char mark[100][100];
bool flag = 0;
int n;
/*
0:ツ湘」
1:ツ右
2:ツ可コ
3:ツ債カ
*/
void saiki(int x,int y,int turn){
	if(flag){
		if(n%2==0)mark[x][y]='#';
		return;
	}
	mark[x][y]='#';
	if( turn == 0 && y==t ){
		l+=2;
		if(x+1>=r){flag=1;}
		saiki(x+1,y,(turn+1)%4);
	}else if(turn == 2 && y==u ){
		r-=2;
		if(x-1<=l){flag=1;}
		saiki(x-1,y,(turn+1)%4);
	}else if(turn == 3 && x == l){
		u-=2;
		if(y-1<=t){flag=1;}
		saiki(x,y-1,(turn+1)%4);
	}else if(turn == 1 && x == r){
		t+=2;
		if(y+1>=u){flag=1;}
		saiki(x,y+1,(turn+1)%4);
	}else {
		if(turn == 0)saiki(x,y-1,turn);
		else if(turn == 1)saiki(x+1,y,turn);
		else if(turn == 2)saiki(x,y+1,turn);
		else if(turn == 3)saiki(x-1,y,turn);
	}
}

int main(){
	cin >> n;
	while(cin >> n){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				mark[j][i]=' ';
		}
		flag = 0;
		l = t = 0;
		r = u = n-1;
		saiki(0,n-1,0);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				cout << mark[j][i];
			cout << endl;
		}
		cout << endl;
	}
}

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

bool pat[104][104];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};

int main() {
    int n, m;
    cin >> n;
    bool lf = false;
    while (n--) {
        cin >> m;
        for (int i=0; i<=m+3; ++i) {
            for (int j=0; j<=m+3; ++j) {
                pat[i][j] = (i == 0 || i == m+3 || j == 0 || j == m+3);
            }
        }
        int x = 2;
        int y = m+1;
        int k = 0;
        while (1) {
            pat[y][x] = true;
            if (pat[y + dy[k] * 2][x + dx[k] * 2]) {
                k = (k + 1) % 4;
            }
            int adj = 0;
            for (int i=0; i<4; ++i) {
                if (pat[y + dy[k] + dy[i]][x + dx[k] + dx[i]]) {
                    adj ++;
                }
            }
            if (1 < adj) {
                break;
            }
            x += dx[k];
            y += dy[k];
        }
        if (lf) {
            cout << endl;
        }
        for (int i=2; i<=m+1; ++i) {
            for (int j=2; j<=m+1; ++j) {
                cout << (pat[i][j] ? "#" : " ");
            }
            cout << endl;
        }
        lf = true;
    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define MAX_N 5500
int n, cnt, cx, cy, cnt2;
bool x[MAX_N][MAX_N];
bool y[MAX_N][MAX_N];
int main() {
	while (cin >> n) {
		if (cnt2) { cout << endl; }
		cnt2++;
		cnt = 0;
		memset(x, true, sizeof(x));
		memset(y, false, sizeof(y));
		for (int i = 10; i < 10 + n; i++) {
			for (int j = 10; j < 10 + n; j++) {
				x[i][j] = false;
			}
		}
		cy = 10 + n;
		cx = 10;
		while (cnt <= MAX_N) {
			while (x[cy - 1][cx] == false && y[cy - 2][cx] == false && y[cy - 1][cx + 1] == false) {
				cy--;
				y[cy][cx] = true;
			}
			while (x[cy][cx + 1] == false && y[cy][cx + 2] == false) {
				cx++;
				y[cy][cx] = true;
			}
			while (x[cy + 1][cx] == false && y[cy + 2][cx] == false && y[cy + 1][cx - 1] == false) {
				cy++;
				y[cy][cx] = true;
			}
			while (x[cy][cx - 1] == false && y[cy][cx - 2] == false) {
				cx--;
				y[cy][cx] = true;
			}
			cnt++;
		}
		for (int i = 10; i < 10 + n; i++) {
			for (int j = 10; j < 10 + n; j++) {
				if (y[i][j] == true) {
					cout << '#';
				}
				else {
					cout << ' ';
				}
			}
			cout << endl;
		}
	}
}

C++: #include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 10000000;
using namespace std;

int main()
{
	char b[100][100];
	int n, d, dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
	
	cin >> d;
	rep(t, d) {
		memset(b, ' ', sizeof(b));
		
		cin >> n;
		rep(i, n) b[0][i]='#';
		int x=0, y=0, nn = n, direct=0;
		
		while (1) {
			for (int i=0; i<nn; i++) {
				b[x][y] = '#';
				x+=dx[direct]; y+=dy[direct];
			}
			x-=dx[direct]; y-=dy[direct];
			direct++; direct%=4;
			
			if (n%2==0 && nn<=2) break;
			
			for (int i=0; i<nn; i++) {
				b[x][y] = '#';
				x+=dx[direct]; y+=dy[direct];
			}
			x-=dx[direct]; y-=dy[direct];
			direct++; direct%=4;
			nn-=2;
			
			if (nn<=1)
				break;
		}
		rep(y, n) {
			rep(x, n)
			cout << b[x][y];
			cout << endl;
		}

	}
	return 0;
}

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++){
      if(j) cout << " ";
      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<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++){
      if(j) cout << " ";
      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(){

  int x;
  cin >> x;

  while(x--){
    init();
    cin >> n;
    solve();
    print();
  }
  return 0;
}