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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

bool guru[110][110];

int main() {
	int d=in();
	int n;
	bool first=true;
	while(d--){
		if(!first)cout<<endl;
		first=false;
		cin>>n;
		int i,j;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				guru[i][j]=false;
			}
		}
		int len=n;
		for(i=0;i<n;i++){
			guru[i][0]=true;
		}
		while(1){
			for(i=0;i<len;i++){
				guru[(n-len)/2][i+(n-len)/2]=true;
			}
			if(len<3)break;
			for(i=0;i<len;i++){
				guru[i+(n-len)/2][n-1-(n-len)/2]=true;
			}
			len-=2;
			for(i=0;i<len;i++){
				guru[n-1-(n-len-2)/2][n-(n-len)/2-i]=true;
			}
			if(len<3)break;
			for(i=0;i<len;i++){
				guru[n-(n-len)/2-i][(n-len-2)/2+2]=true;
			}
			len-=2;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(guru[i][j])cout<<"#";
				else cout<<" ";
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
    int d,N;
    cin>>d;
    for(int i=0;i<d;i++){
        int N;
        cin>>N;
        char fie[200][200];
        for(int i=0;i<200;i++){
            for(int j=0;j<200;j++)fie[i][j]=' ';
        }
        for(int j=0;j<N;j++)fie[j][0]='#';
        int x=0,y=0;
        for(int j=0;;j++){
            int p=(N-1)-(j/2*2);
            if(p<=0||(p==1&&j%2==1&&N%2==0))break;
            for(int k=0;k<p;k++){
                y+=dy[j%4],x+=dx[j%4];
                fie[y][x]='#';
            }
        }
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                cout<<fie[j][k];
            }
            puts("");
        }
        puts("");
    }
}

C++: #include <iostream>
#include <cstring>
using namespace std;
char buf[150][150];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
bool check(int tx,int ty)
{
	if(tx<0||ty<0)return false;
	return buf[tx][ty]=='#';
}
void solve(int x)
{
	memset(buf,' ',sizeof(buf));
	for(int i=1;i<=x;i++)
	{
		for(int j=1;j<=x;j++)
		{
			buf[i][j]='#';
		}
	}
	int X=x,Y=2;
	int cnt=0;
	for(int p=0;p<=10000;p++)
	{
		if(X>x+10||Y>x+10||X<0||Y<0)break;
		if(x%4==1&&X==(x+3)/2&&Y==(x+1)/2)break;
		if(x%4==3&&X==(x+1)/2&&Y==(x+3)/2)break;
		buf[X][Y]=' ';
		X+=dx[cnt];Y+=dy[cnt];
		if(check(X+dx[cnt],Y+dy[cnt])&&!check(X+dx[cnt]*2,Y+dy[cnt]*2))
		{
			cnt++;
			cnt%=4;
		}
	}
	for(int i=1;i<=x;i++)
	{
		for(int j=1;j<=x;j++)
		{
			cout << buf[i][j];
		}
		cout << endl;
	}
	return;
}
int main()
{
	int q;
	cin >> q;
	for(int i=0;i<q;i++)
	{
		int k;
		cin >> k;
		solve(k);
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

bool guru[110][110];

int main() {
	int d=in();
	int n;
	while(d--){
		cin>>n;
		int i,j;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				guru[i][j]=false;
			}
		}
		int len=n;
		for(i=0;i<n;i++){
			guru[i][0]=true;
		}
		while(1){
			for(i=0;i<len;i++){
				guru[(n-len)/2][i+(n-len)/2]=true;
			}
			if(len<3)break;
			for(i=0;i<len;i++){
				guru[i+(n-len)/2][n-1-(n-len)/2]=true;
			}
			len-=2;
			for(i=0;i<len;i++){
				guru[n-1-(n-len-2)/2][n-(n-len)/2-i]=true;
			}
			if(len<3)break;
			for(i=0;i<len;i++){
				guru[n-(n-len)/2-i][(n-len-2)/2+2]=true;
			}
			len-=2;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(guru[i][j])cout<<"#";
				else cout<<" ";
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int main(){
	int n;
	cin>>n;
	rep(l,n){
		if(i) cout<<endl;
		int m;
		cin>>m;
		// cout<<m<<endl;
		if(m==1){
			cout<<"#\n";
			continue;
		}
		if(m==2){
			cout<<"##\n";
			cout<<"# \n";
			continue;
		}
		if(m==3){
			/*
			###
			# #
			# #
			*/
			cout<<"###\n";
			cout<<"# #\n";
			cout<<"# #\n";
			// cout<<"\n";
			continue;
		}
		if(m==4){
			cout<<"####\n";
			cout<<"#  #\n";
			cout<<"#  #\n";
			cout<<"# ##\n";
			// cout<<endl;
			continue;
		}
		vector<vector<char> > vv;
		initvv(vv,m,m);
		rep(i,m){
			rep(j,m) vv[i][j]=' ';
		}
		rep(i,m){
			vv[0][i]='#';
			vv[m-1][i]='#';
			vv[i][m-1]='#';
			vv[i][0]='#';
		}
		vv[m-1][1]=' ';
		int x=m-1,y=2;
		int c=0;
		while(1){
			// cout<<x<<" "<<y<<endl;
			if(vv[x+dx[c]*2][y+dy[c]*2]==' '){
				x+=dx[c];
				y+=dy[c];
				vv[x][y]='#';
			}
			else if(vv[x+2*dx[(c+1)%4]][y+2*dy[(c+1)%4]]==' '&&vv[x+dx[(c+1)%4+dx[(c+2)%4]]][y+dy[(c+1)%4]+dy[(c+2)%4]]==' '){
				c++;
				c%=4;
				x+=dx[c];
				y+=dy[c];
				vv[x][y]='#';
			}
			else{
				break;
			}
		}
		/*
		######
		#    #
		# ## #
		# #  #
		# #  #
		# ####
		*/
		rep(i,m){
			rep(j,m){
				cout<<vv[i][j];
			}
			cout<<endl;
		}
		cout<<endl;
	}
}