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, 101)
	}
	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>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int n,d;

bool inside(int x,int y){
	if(x>=0 && x<d && y>=0 && y<d)return true;
	else return false;
}

int main(){
	cin>>n;
	rep(p,n){
		cin>>d;
		char ch[d][d];
		rep(i,d)rep(j,d)ch[i][j]='.';
		int dir=0;
		int x=0,y=d-1;
		while(1){
			int check=0;
			if(dir==0){
				while(inside(x,y)){
					ch[y][x]='#';
					if(inside(x,y-1) && ch[y-1][x]=='.'){
						ch[y][x+1]='-';
						y--;
						check|=1;
					}else{if(ch[y][x+1]!='-')x++;break;} 
				}
			}else if(dir==1){
				while(inside(x,y)){
					ch[y][x]='#';
					if(inside(x+1,y) && ch[y][x+1]=='.'){
						ch[y+1][x]='-';
						x++;
						check|=2;
					}else{if(ch[y+1][x]!='-')y++;break;}
				}
			}else if(dir==2){
				while(inside(x,y)){
					ch[y][x]='#';
					if(inside(x,y+1) && ch[y+1][x]=='.'){
						ch[y][x-1]='-';
						y++;
						check|=4;
					}else{if(ch[y][x-1]!='-')x--;break;}
				}
			}else{
				while(inside(x,y)){
					ch[y][x]='#';
					if(inside(x-1,y) && ch[y][x-1]=='.'){
						ch[y-1][x]='-';
						x--;
						check|=8;
					}else{if(ch[y-1][x]!='-')y--;break;}
				}
			}
			dir++;
			dir%=4;
			if(check==0)break;
		}
		rep(i,d){
			rep(j,d){
				if(ch[i][j]=='#')cout<<'#';
				else cout<<' ';
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstring>

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int a[101][101];
	int dx[4] = {0,1,0,-1};
	int dy[4] = {-1,0,1,0};
	
	bool first = true;

	rep(i,n)
	{
		int r;
		cin >> r;
		int r2 = r;

		memset(a,0,sizeof(a));

		if(r == 1)
		{
			if(first) first = false;
			else cout << endl;
			cout << "#" << endl;
		}
		else if(r == 2)
		{
			if(first) first = false;
			else cout << endl;
			cout << "# " << endl << "# " << endl;
		}
		else
		{
			int y = r-1;
			int x = 0;
			a[y][x] = 1;

			int dir = 0;

			rep(j,r-1)
			{
				y += dy[dir%4];
				x += dx[dir%4];
				a[y][x] = 1;
			}

			dir++;
			r--;
			
			if(r%2 == 1)
			{
				while(true)
				{
					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;

					if(r == 1) break;

					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;
					r -= 2;
				}
			}
			else
			{
				while(true)
				{
					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;

					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}

					if(r == 2 ) break;

					dir++;
					r -= 2;
				}
			}
			
			if(first) first = false;
			else cout << endl;

			rep(j,r2)
			{
				rep(k,r2)
				{
					if(a[j][k] == 1) cout << "#";
					else cout << " ";
				}
				cout << endl;
			}
		}	
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>

char MAP[104][104];
int nx,ny,vx=0,vy=-1;
void rotate(){ //EñèÉñ]·é
	int tx=vx,ty=vy;
	vx=-ty;vy=tx;
}
int main(){
	int s; //}bvÌL³
	int n; //·éÂ
	int t; //I¹»èp
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&s);
		memset(MAP,'#',104*104);
		for(int x=1;x<1+s+2;x++){
			for(int y=1;y<1+s+2;y++){
				MAP[x][y]=' ';
			}
		}
		nx=2,ny=s+1;t=0;vx=0;vy=-1;
		while(1){
			MAP[nx][ny]='#';
			if(MAP[nx+vx*2][ny+vy*2]=='#'){
				if(t>0) break;
				t=2;
				rotate();
			} else {
				t--;
				nx+=vx;ny+=vy;
			}
		}
		//\¦
		if(i!=0) puts("");
		for(int y=2;y<1+s+1;y++){
			for(int x=2;x<1+s+1;x++){
				printf("%c",MAP[x][y]);
			}
			puts("");
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int m,n,x,y,p,xx,yy,d,l;
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
main(){
  cin>>m;
  while(m--){
    cin>>n;l=0;
    string s[n];
    r(i,n)r(j,n)s[i]+='#';
    s[n-1][1]=' ';
    xx=0,yy=n-1,d=0;
    while(1){
      int c=0;
      r(i,4){
        if(!l)c--;
        y=dy[i]+yy,x=dx[i]+xx;
        if(y<0||y>=n||x<0||x>=n){
          c++;
          continue;
        }
        else if(s[y][x]==' ')c++;
      }
      if(c>=3)break;
      y=dy[d]+yy,x=dx[d]+xx;
      if(y<0||y>=n||x<0||x>=n)d=(d+1)%4;
      else if(s[y][x]==' ')d=(d+1)%4;
      else{
        yy=y+dy[d],xx=x+dx[d];
        if(yy>=0&&yy<n&&xx>=0&&xx<n&&s[yy][xx]!=' '){
          p=(d+1)%4;
          yy=y+dy[p],xx=x+dx[p];
          s[yy][xx]=' ';
        }
        yy=y,xx=x;
      }l++;
    }
    r(i,n)cout<<s[i]<<endl;
  }
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int h, w;

bool can(int y, int x){
	return (0 <= y && y < h && 0 <= x && x < w);
}

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

signed main() {
	int t, n;
	cin >> t;
	rep(k, 0, t){
		int a[110][110]={};
		cin >> n;
		h = w = n;
		vi d;
		int tmp = n;
		d.push_back(tmp);
		while(1){
			if(tmp <= 2){
				d.push_back(tmp);
				break;
			}
			rep(i,0,2) d.push_back(tmp);
			tmp -= 2;
		}
		int y = n - 1, x = 0;
		a[y][x] = 1;
		rep(i, 0, d.size()){
			int dir = i % 4;
			rep(j, 0, d[i] - 1){
				y += dy[dir];
				x += dx[dir];
				a[y][x] = 1;
			}
		}
		rep(i, 0, n){
			rep(j, 0, n){
				cout << (a[i][j] ? '*':' ') ;
			}
			cout << endl;
		}
	}
}