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 <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

char maze[110][110];
int dx[] = {0,1,0,-1} , dy[] = {-1,0,1,0};
int size;

bool over(int x,int y){
  return x < 0 || size <= x || y < 0 || size <= y;
}
bool space(int x,int y){
  int cnt = 0;
  rep(i,4){
    int nx = x + dx[i], ny = y + dy[i];
    if(maze[ny][nx] == '#')
      cnt ++;
  }
  return cnt > 1;
}
void dfs(int x,int y,int d){
  if(size <= x) 
    dfs(x-1,y,2);
  if(y < 0)
    dfs(x,y+1,1);
  if(size <= y)
    dfs(x,y-1,3);
  if(space(x,y))
    return ;
  if(over(x,y))return;
  maze[y][x] = '#';
  
  int nnx = x + 2 * dx[d] , nny = y + 2 * dy[d];
  if(maze[nny][nnx] == '#')
    d = (d+1)%4;
  dfs(x+dx[d],y+dy[d],d);

}

void solve(int n){
  size = n;
  dfs(0,n-1,0);
  rep(i,n){
    rep(j,n){
      cout<<maze[i][j];
    }
    cout<<endl;
  }
}

int main(void){
  int n,in;
  cin>>n;
  rep(time,n){
    cin>>in;
    rep(i,in)rep(j,in)maze[i][j] = ' ';
    solve(in);
   
    if(!time)cout<<endl;
  }
}

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 << " ";
            }
            cout << endl;
        }
        if(k!=d-1)cout << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

char ans[110][110];
int n;

bool isSpace(int x, int y){
  if(x < 0 || y < 0) return true;
  if(x >= n|| y >=n) return true;
  return ans[y][x] == ' ';
}

int main(){
  int d; cin>>d;
  int cc = 0;
  while(d --> 0){
    cin>>n;
    if(cc++ != 0) puts("");
    if(n == 1){
      puts("#");
    }else if(n == 2){
      puts("##");
      puts("# ");
    }else{
      const int dx[4] = {0,1,0,-1};
      const int dy[4] = {-1,0,1,0};
      memset(ans, '#', sizeof(ans));
      REP(i,n) ans[i][n] = '\0';
      int i = 0;
      int x = 1;
      int y = n-1;
      ans[y][x] = ' ';
      while(true){
        if(isSpace(x + dx[i], y + dy[i]) ||
           isSpace(x + dx[i] + dx[i], y + dy[i] + dy[i]))
          break;

        while(!isSpace(x + dx[i] + dx[i], y + dy[i] + dy[i])){
          x = x + dx[i]; y = y + dy[i];
          ans[y][x] = ' ';
        }

        i = (i + 1) % 4;
      }
      REP(i,n) puts(ans[i]);
    }
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

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

int main(){
	int n, d;
	cin >> d;
	rep(t, d){
		if(t != 0) cout << endl;
		cin >> n;
		if(n == 2){
			cout << "##\n# \n";
			continue;
		}
		fill(&field[0][0], &field[199][199] + 1, '#');
		rep(i, n + 2){
			rep(j, n + 2) field[i+1][j+1] = ' ';
		}
		int x = 2;
		int y = 2 + n - 1;
		int cnt = 0;
		int dire = 0;
		while(true){
			cnt = 0;
			while(field[y + 2 * dy[dire]][x + 2 * dx[dire]] != '#'){
				cnt++;
				field[y][x] = '#';
				y += dy[dire];
				x += dx[dire];
			}
			field[y][x] = '#';
			if(cnt < 2) break;
			dire = (dire + 1) % 4;
		}
		rep(i, n){
			rep(j, n) cout << field[i+2][j+2];
			cout << endl;
		}
	}
	return 0;
}