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
		len := 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++
				len = 1
			} else if out[nrow+dy[dir%4]][ncol+dx[dir%4]]=="#" {
				if len < 3 {
					break
				}
				dir++
				len = 1
			} else {
				row=nrow
				col=ncol
				out[row][col]="#"
				len++
			}
		}
		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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,(n))
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int n, d;
vector<string> s;

bool outOfRange(int y, int x){
	if(y < 0 || y >= n || x < 0 || x >= n) return true;
	return false;
}

bool check(int ny, int nx, int dir){
	if(outOfRange(ny, nx)) return true;
	for(int i = 0; i < 4; i++){
		if(i == (dir+2)%4) continue;
		int nny = ny + dy[i], nnx = nx + dx[i];
		if((!outOfRange(nny, nnx)) && s[nny][nnx] == '#') return true;
	}
	return false;
}

int main(){
	cin>>d;
	for(int i = 0; i < d; i++){
		if(i!=0) printf("\n");
		cin>>n;
		s = vector<string>(n,string(n, ' '));
		pii pos = pii(n-1, 0);
		int dir = 0;
		while(1){
			if(s[pos.fi][pos.se]=='#') break;
			s[pos.fi][pos.se] = '#';
			int ny = pos.fi+dy[dir], nx = pos.se+dx[dir], cnt = 4;
			while(check(ny, nx, dir) &&(--cnt)){
				dir++; dir%=4;
				ny = pos.fi+dy[dir]; nx = pos.se+dx[dir];

			}
			if(cnt == 0) break;
			pos=pii(ny ,nx);
		}
		rep(i, n) cout<<s[i]<<endl;
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>

/*
 
 #####
 #   #
 # # #
 # # #
 # ###
 
 ######
 #    #
 # ## #
 # #  #
 # #  #
 # ####
 
 */
using namespace std;


void f(char guruguru[100][100], int l, int d, int x, int y){
    while(1){
        if(l<=0)return;
        
        if(d==0){//右下
            for(int i=0; i<l; i++){
                guruguru[y][x+i]='#';
            }
            x=x+(l-1);
            
            if(l==2)return;
            
            for(int i=0; i<l; i++){
                guruguru[y+i][x]='#';
            }
            y=y+(l-1);
            l=l-2;
            d=1;
            //f(guruguru,l,d,x,y);
        }
        
        if(d==1){//左上
            
            
            for(int i=0; i<l; i++){
                guruguru[y][x-i]='#';
            }
            x=x-(l-1);
            
            if(l<=2)return;
            
            for(int i=0; i<l; i++){
                guruguru[y-i][x]='#';
            }
            y=y-(l-1);
            
            l=l-2;
            d=0;
            //f(guruguru,l,d,x,y);
        }
    }
}

void f0(char guruguru[100][100], int l, int d, int x, int y){
    for(int i=0; i<l; i++){
        guruguru[i][0]='#';
    }
    
    f(guruguru,l,0,0,0);
}

/*
 int main(){
 
 for(int i=0; i<100; i++){
 for(int j=0; j<100; j++){
 guruguru_0[i][j]=' ';
 guruguru_1[i][j]=' ';
 guruguru_2[i][j]=' ';
 guruguru_3[i][j]=' ';
 }
 }
 
 
 //f0(guruguru_0, 100, 0, 0, 0);
 //f0(guruguru_3, 99, 0, 0, 0);
 //f0(guruguru_2, 98, 0, 0, 0);
 //f0(guruguru_1, 97, 0, 0, 0);
 
 
 
 int n;
 cin>>n;
 for(int roop=0; roop<n; roop++){
 int l;
 cin>>l;
 if(l%4==0){
 int x=50-l/2;
 int y=50-l/2;
 for(int i=y; i<y+l; i++){
 for(int j=x; j<x+l; j++){
 cout<<guruguru_0[i][j];
 }
 cout<<endl;
 }
 cout<<endl;
 }else if(l%4==1){
 int x=50-l/2-2;
 int y=50-l/2-2;
 for(int i=y; i<y+l; i++){
 for(int j=x; j<x+l; j++){
 cout<<guruguru_1[i][j];
 }
 cout<<endl;
 }
 cout<<endl;
 } else if(l%4==2){
 int x=50-l/2-1;
 int y=50-l/2-1;
 for(int i=y; i<y+l; i++){
 for(int j=x; j<x+l; j++){
 cout<<guruguru_2[i][j];
 }
 cout<<endl;
 }
 cout<<endl;
 }else if(l%4==3){
 int x=50-l/2-1;
 int y=50-l/2-1;
 for(int i=y; i<y+l; i++){
 for(int j=x; j<x+l; j++){
 cout<<guruguru_3[i][j];
 }
 cout<<endl;
 }
 cout<<endl;
 }
 }
 
 }
 */
int main(){
    
    int n;
    cin>>n;
    for(int roop=0; roop<n; roop++){
        int l;
        cin>>l;
        char guruguru[100][100];
        //memcpy(guruguru,init,sizeof(init));
        for(int i=0; i<l; i++){
            for(int j=0; j<l; j++){
                guruguru[i][j]=' ';
            }
        }
        
        f0(guruguru,l,0,0,0);
        
        for(int i=0; i<l; i++){
            for(int j=0; j<l; j++){
                cout<<guruguru[i][j];
            }
            cout<<endl;
        }
        if(roop==n-1)break;
        cout<<endl;
    }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,int> P;

static const double eps = 10e-9;

const int tgt[][2] = {{0,1},{1,0},{0,-1},{-1,0}};

void dfs(int stage[100][100],int x,int y,int dir,int w){

	printf("x:%d y:%d\n",x,y);
	if(stage[y][x]) return;	

	int dx;
	int dy;

	int c=0;
	for(int i=0;i<4;i++){
		dx = x+tgt[i][0];
		dy = y+tgt[i][1];
		if(dx < 0 || dx >= w || dy < 0 || dy >= w) continue;
		if(stage[dy][dx]) c++;
	}

	if(c>=2) return;

	dx = x+tgt[dir][0];
	dy = y+tgt[dir][1];

	int jx = x+tgt[dir][0]*2;
	int jy = y+tgt[dir][1]*2;

	stage[y][x] = 1;

	if(!(jx < 0 || jx >= w || jy < 0 || jy >= w) && stage[jy][jx]){
		dx = x+tgt[(dir+1)%4][0];
		dy = y+tgt[(dir+1)%4][1];
		dfs(stage,dx,dy,(dir+1)%4,w);
	}

	else if(dx < 0 || dx >= w || dy < 0 || dy >= w){
		dx = x+tgt[(dir+1)%4][0];
		dy = y+tgt[(dir+1)%4][1];
		dfs(stage,dx,dy,(dir+1)%4,w);
	}


	else dfs(stage,dx,dy,dir,w);

}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int w;
		scanf("%d",&w);
		int x=0;
		int y=0;

		int stage[100][100];
		memset(stage,0,sizeof(stage));
		int dir = 0;
		int change = 0;

		dfs(stage,0,0,0,w);
		for(int ty = w-1; ty>=0;ty--){
			for(int tx=0; tx<w;tx++){
				cout << (stage[ty][tx] ? '#' : ' ');
			}
			cout << endl;
		}
	}
}