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 <iostream>
#include <vector>
#include <string>
using namespace std;

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

inline bool in(const int x, const int y, const int w, const int h)
{
  if (0 <= x && x < w && 0 <= y && y < h)
    return true;
  return false;
}

int main()
{
  int d;
  cin >> d;
  while (d--) {
    int n;
    cin >> n;
    vector<string> p(n, string(n, '#'));

    bool update = true;
    int x = 1, y = n-1, dir = 3, cnt = 0;
    while (update) {
      update = false;
      for (int i = 0; i < 4 && !update; ++i) {
	int xx = x + dx[dir], yy = y + dy[dir];
	if (in(xx, yy, n, n) && p[yy][xx] == '#' &&
	    in(xx+dx[dir], yy+dy[dir], n, n) && p[yy+dy[dir]][xx+dx[dir]] == '#') {
	  p[y][x] = ' ';
	  x += dx[dir];
	  y += dy[dir];
	  update = true;
	} else {
	  dir = (dir+1) % 4;
	}
      }
    }

    p[y][x] = ' ';
    for (int i = 0; i < n; ++i)
      cout << p[i] << endl;

    if (d != 0)
      cout << endl;
  }
  return 0;
}

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

char field[101][101];
int N, n, now;
int x, y;
bool flag;

void print(){
  for(int i = 0 ; i <= n ; i++){
    for(int j = 0 ; j <= n ; j++){
      cout << field[i][j];
    }
    cout << endl;
  }
  cout << endl;
}

void init(){
  flag = false;
  for(int i = 0 ; i < 101 ; i++){
    for(int j = 0 ; j < 101 ; j++){
      field[i][j] = ' ';
    }
  }
  for(int i = n ; i >= 0 ; i--){
    field[i][0] = '#';
  }
  for(int i = 0 ; i < n ; i++){
    field[0][i] = '#';
  }
  for(int i = 0 ; i <= n ; i++){
    field[i][n] = '#';
  }
}

void left(){
  int j;
  for(j = x ; field[y][j-1] != '#' ; j--){
    field[y][j] = '#';
  }
  x = j+1;
}

void up(){
  int i;
  for(i = y ; field[i-1][x] != '#' ; i--){
    field[i][x] = '#';
  }
  y = i+1;
}

void right(){
  int j;
  for(j = x ; field[y][j+1] != '#' ; j++){
    field[y][j] = '#';
  }
  x = j-1;  
}

void down(){
  int i;
  for(i = y ; field[i+1][x] != '#' ; i++){
    field[i][x] = '#';
  }
  y = i-1;
}

    
int main(){
  cin >> N;
  while(N--){
    cin >> n;
    n--;
    
    if(n == 0) cout << '#' << endl << endl;
    else if(n == 1){
      cout << "##" << endl << "# " << endl << endl;
    }
    else{
    init();
    x = n, y = n;
    int cnt = 3;
    while(1){
      if(cnt == n+1) break;
      left();
      cnt++;
      if(cnt == n+1) break;
      up();
      cnt++;
      if(cnt == n+1) break;
      right();
      cnt++;
      if(cnt == n+1) break;
      down();
      cnt++;
    }
    print();
    }
  } 
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
int N;
bool fld[100][100];

bool end(int y,int x){
	int cnt = 0;
	for(int i=0;i<4;i++){
		int ny,nx;
		ny = y+dy[i]; nx = x+dx[i];
		if(ny<0 || N<=ny || nx<0 || N<=nx) continue;
		if(fld[ny][nx]) cnt++;
	}
	if(cnt>=2) return true;
	return false;
}

void dfs(int n,int dir,int y,int x){
	if(n<2) return;
	int cnt = 2;
	if(n==N) cnt = 3;
	for(int i=0;i<cnt;i++){
		for(int j=0;j<n-1;j++){
			y += dy[dir]; x += dx[dir];
			if(end(y,x)) return;
			fld[y][x] = true;
		}
		dir = (dir+1)%4;
	}
	dfs(n-2,dir,y,x);
}

int main(){
	cin>>N;
	fld[N-1][0] = true; dfs(N,0,N-1,0);
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(fld[i][j]) printf("#");
			else printf(" ");
		}puts("");
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  const int dx[4] = {1,0,-1,0};
  const int dy[4] = {0,1,0,-1};
  int d;
  string s;
  cin>>d;
  s = "";
  for(int i=0;i<d;i++) s+=" ";
  vector<string> spiral(d);
  for(int i=0;i<d;i++)spiral[i] = s;
  int x=0,y=d-1,dir=2,i=0;
  while(i<=d){
    spiral[y][x] = '#';
    if((i<4&&(y==0||y==d-1)&&(x==0||x==d-1))||(i>3&&spiral[y+2*dy[dir]][x+2*dx[dir]]=='#')){
      dir = (++dir)%4;
      i++;
      if(d==1)break;
    }
    x+=dx[dir];
    y+=dy[dir];
  }
  for(int y=0;y<d;y++)
    cout<<spiral[y]<<endl;
  return 0;
}

C++: #include<iostream>
using namespace std;
char t[100][100];
int n,a,x,y,d,ny,nx,flg,cnt;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};

void rec(int y,int x,int d){

  
  /*
    for(int i=0;i<a;i++){
      for(int j=0;j<a;j++){
	cout<<t[i][j];
      }
      cout<<endl;
    }

    cout<<y<<' '<<x<<' '<<d<<endl;*/
  cnt=0;
  for(int i=0;i<a;i++){
    t[y][x]='#';cnt++;
    ny=y+dy[d]*2;
    nx=x+dx[d]*2;
    if(t[ny][nx]=='#'){
      break;
    }
    y=y+dy[d];
    x=x+dx[d];
  }
  if(cnt>=3)rec(y,x,(d+1)%4);
}

int main(){
  cin>>n;
  while(n--){
    cin>>a;
    if(a==1){
      cout<<'#'<<endl;
      continue;
    }else if(a==2){
      cout<<"##"<<endl;
      cout<<"# "<<endl;
      continue;
    }else if(a==4){
      cout<<"####"<<endl;
      cout<<"#  #"<<endl;
      cout<<"#  #"<<endl;
      cout<<"# ##"<<endl;
      continue;
    }

    for(int i=0;i<100;i++)
      for(int j=0;j<100;j++)
	t[i][j]=' ';
    
    t[a-1][0]=' ';
    x=0;y=a-1;
    
    for(int i=0;i<a;i++){
      t[a-1][i]=t[i][a-1]='#';
      t[0][i]=t[i][0]='#';
    }
    t[a-1][1]=' ';
    
    rec(a-1,2,0);
    



    for(int i=0;i<a;i++){
      for(int j=0;j<a;j++){
	cout<<t[i][j];
      }
      cout<<endl;
    }
    if(n>=1)cout<<endl;
  }
  return 0;
}