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

int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int main() {
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		if (b)cout << endl;
		int c;
		cin >> c;
		bool d[100][100]{};
		int x = c - 1, y = 0;
		for (int i = 0;i<10000; i++) {
			while (1) {
				d[x][y] = true;
				if (x + dx[i%4] < 0 || x + dx[i%4] >= c || y + dy[i%4] < 0 || y + dy[i%4] >= c)break;
				int sum = 0;
				for (int p = 0; p < 4; p++) {
					if (x + dx[i % 4] + dx[p] >= 0 && x + dx[i % 4] + dx[p] < c && y + dy[i % 4] + dy[p] >= 0 && y + dy[i % 4] + dy[p] < c&&d[x + dx[i % 4] + dx[p]][y + dy[i % 4] + dy[p]]) {
						sum++;
					}
				}
				if (sum > 1)break;
				x += dx[i % 4]; y += dy[i % 4];
			}
		}
		for (int k = 0; k < c; k++) {
			for (int l = 0; l < c; l++) {
				if (d[k][l])cout << "#";
				else cout << " ";
			}
			cout << endl;
		}
	}
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;

typedef complex<int> P;
int n;

bool Outside(P &p) {
return p.real() < 0 || p.real() >= n || p.imag() < 0 || p.imag() >= n; 
}

bool isWall(vector<string>& v,P &p){
	if(Outside(p)) return false;
	return v[p.imag()][p.real()] == '#';
}

int main(){
	int t; cin>>t;
	while(t--){
		cin>>n;
		vector<string> v(n,string(n,' '));

		P current(0,n-1),e(0,1);
		P d(0,-1);
		if(n == 1){
			v[0][0] = '#';
		} else{
			while(true){
				P next = current + d;
				if(isWall(v,next)) break;
				v[current.imag()][current.real()] = '#';
				bool ok = !Outside(next);
				if(ok){
					FOR(i,4){
						d *= e;
						P ne = next + d;
						if(ne == current) continue;
						if(isWall(v,ne))ok = false;
					}
				}

				if(!ok){
					d *= e;
				} else {
					current = next;
				}
			}
		}
		FOR(i,n) cout << v[i] << endl;

		if(t!=0)puts("");
	}

	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
using namespace std;

#define mk make_pair



int main(){
    int time;
    cin>>time;
    for(int p=0;p<time;p++){
    
    
        if(p!=0){cout<<endl;}
    int n;
    cin>>n;
    char a[1000][1000];
    fill(&a[0][0],&a[999][1000],' ');
    char t='u';
    a[n+99][100]='#';
    pair<int,int> w=mk(n+99,100);
        int j=0;
    while(j!=2){
        if(t=='u'){
            if(a[w.first-1][w.second]=='#'){break;}
            if(a[w.first-2][w.second]=='#' || w.first==100 || a[w.first-1][w.second+1]=='#'){t='r'; j++; continue;}
            w.first--;
        }
        if(t=='r'){
            if(a[w.first][w.second+1]=='#'){break;}
            if(a[w.first][w.second+2]=='#' || w.second==99+n || a[w.first+1][w.second+1]=='#'){t='d'; j++; continue;}
            w.second++;
        }
        if(t=='d'){
            if(a[w.first+1][w.second]=='#'){break;}
            if(a[w.first+2][w.second]=='#' || w.first==99+n || a[w.first+1][w.second-1]=='#'){t='l'; j++; continue;}
            w.first++;
        }
        if(t=='l'){
            if(a[w.first][w.second-1]=='#'){break;}
            if(a[w.first][w.second-2]=='#' || w.second==100 || a[w.first-1][w.second-1]=='#'){t='u'; j++; continue;}
            w.second--;
        }
        a[w.first][w.second]='#';
        j=0;
    }
    
    for(int i=100;i<n+100;i++){
        for(int t=100;t<n+100;t++){
            cout<<a[i][t];
        }
        cout<<endl;
    }
        
        
        
    }
    
    
    return 0;
}

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

bool field[100][100];

void migi(int y,int x,int j)
{
	for(int i=1;i<=j;i++){
		field[y][x+i] = 1;
	}
}
void sita(int y,int x,int j)
{
	if(j <= 1)
		return;
	for(int i=1;i<=j;i++){
		field[y+i][x] = 1;
	}
}
void hidari(int y,int x,int j)
{
	for(int i=1;i<=j;i++){
		field[y][x-i] = 1;
	}
}
void ue(int y,int x,int j)
{
	if(j <= 1)
		return;
	for(int i=1;i<=j;i++){
		field[y-i][x] = 1;
	}
}	
int main()
{
	int a;
	cin >> a;
	for(int i=0;i<a;i++){
		int n;
		cin >> n;
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				field[j][k] = 0;
			}
		}
		int y=n-1,x=0;
		for(int j=0;j<n;j++){
			field[y-j][x] = 1;
		}
		y = 0;
		
		for(int j=n-1;j>=0;j-=2){
			migi(y,x,j);
			x = x+j;
			sita(y,x,j);
			y = y+j;			
			j-=2;
			hidari(y,x,j);
			x = x-j;
			ue(y,x,j);
			y = y-j;
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(field[i][j] == 1)
					cout << '#';
				else
					cout << ' ';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

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;
    if(time)cout<<endl;

    rep(i,in)rep(j,in)maze[i][j] = ' ';
    solve(in);
   
  }
}