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<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

char f[100][100];
int dw[4] = {0, 1, 0, -1};
int dh[4] = {-1, 0, 1, 0};
signed main(void){
  int i, j;
  int(d);
  for(int testcase = 0;testcase < d;testcase++){
    if(testcase != 0)puts("");
    int(n);
    rep(i, n)rep(j, n)f[i][j] = ' ';
    int noww = 0, nowh = n - 1, k = 0;

    bool is = false;
    for(;;){
      //printf("%d %d %d\n", nowh, noww, k);
      f[nowh][noww] = '#';
      if(0 > nowh + dh[k] || nowh + dh[k] >= n || 0 > noww + dw[k] || noww + dw[k] >= n){
        //puts("a");
        if(is)break;
        is = true;
        k = (k + 1) % 4;
        continue;
      }
      if(0 <= nowh + dh[k] * 2 && nowh + dh[k] * 2 < n)
      if(0 <= noww + dw[k] * 2 && noww + dw[k] * 2 < n)
      if(f[nowh + dh[k] + dh[k]][noww + dw[k] + dw[k]] == '#'){
        //puts("b");
        if(is)break;
        is = true;
        k = (k + 1) % 4;
        continue;
      }
      if(0 <= nowh + dh[k] + dh[(k + 1) % 4] && nowh + dh[k] + dh[(k + 1) % 4] < n)
      if(0 <= noww + dw[k] + dw[(k + 1) % 4] && noww + dw[k] + dw[(k + 1) % 4] < n)
      if(f[nowh + dh[k] + dh[(k + 1) % 4]][noww + dw[k] + dw[(k + 1) % 4]] == '#'){
        //puts("c");
        if(is)break;
        is = true;
        k = (k + 1) % 4;
        continue;
      }
      if(0 <= nowh + dh[(k + 3) % 4] && nowh + dh[(k + 3) % 4] < n)
      if(0 <= noww + dw[(k + 3) % 4] && noww + dw[(k + 3) % 4] < n)
      if(f[nowh + dh[(k + 3) % 4]][noww + dw[(k + 3) % 4]] == '#'){
        //puts("d");
        if(is)break;
        is = true;
        k = (k + 1) % 4;
        continue;
      }
      //puts("e");
      is = false;
      nowh += dh[k]; noww += dw[k];
    }

    rep(i, n){
      rep(j, n)printf("%c", f[i][j]);
      puts("");
    }

//*/

//*/ break;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <cstring>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
int nx,ny,nr;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int a[100][100];
bool plot(int x, int y, int r, int n){
  int count = 0;
  bool flag = true;
  if((x+2*dx[r]>=0&&x+2*dx[r]<n)&&
      y+2*dy[r]>=0&&y+2*dy[r]<n&&a[x+2*dx[r]][y+2*dy[r]]==1)
    return false;
  x+=dx[r]; y+=dy[r];
  while((x>=0&&x<n)&&(y>=0&&y<n)){
    if((x+2*dx[r]>=0&&x+2*dx[r]<n)&&y+2*dy[r]>=0&&y+2*dy[r]<n&&a[x+2*dx[r]][y+2*dy[r]]==1) flag = false;
    a[x][y] = 1;
    x+=dx[r]; y+=dy[r];
    count++;
    if(!flag) break;
  }
  x-=dx[r];y-=dy[r]; nx=x; ny=y; nr=(r+1)%4;
  if(count<2) return false;
  return true;
}
int main(void){
  int d;
  cin>>d;
  while(d--){
    int n;
    cin>>n;
    memset(a,0,sizeof(a));
    a[0][n-1]=1;
    nx=0; ny=n-1; nr=3;
    while(plot(nx,ny,nr,n));
    if(n==2) a[1][0]=1;
    REP(i,n){
      REP(j,n)
        printf("%c",(a[j][i]==1)?'#':' ');
      cout << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define MAX_N 5500
int n, cnt, cx, cy;
bool x[MAX_N][MAX_N];
bool y[MAX_N][MAX_N];
int main() {
	while (cin >> n) {
		cnt = 0;
		memset(x, true, sizeof(x));
		memset(y, false, sizeof(y));
		for (int i = 10; i < 10 + n; i++) {
			for (int j = 10; j < 10 + n; j++) {
				x[i][j] = false;
			}
		}
		cy = 10 + n;
		cx = 10;
		while (cnt <= MAX_N) {
			while (x[cy - 1][cx] == false && y[cy - 2][cx] == false && y[cy - 1][cx + 1] == false) {
				cy--;
				y[cy][cx] = true;
			}
			while (x[cy][cx + 1] == false && y[cy][cx + 2] == false) {
				cx++;
				y[cy][cx] = true;
			}
			while (x[cy + 1][cx] == false && y[cy + 2][cx] == false && y[cy + 1][cx - 1] == false) {
				cy++;
				y[cy][cx] = true;
			}
			while (x[cy][cx - 1] == false && y[cy][cx - 2] == false) {
				cx--;
				y[cy][cx] = true;
			}
			cnt++;
		}
		for (int i = 10; i < 10 + n; i++) {
			for (int j = 10; j < 10 + n; j++) {
				if (y[i][j] == true) {
					cout << '#';
				}
				else {
					cout << ' ';
				}
			}
			cout << endl;
		}
	}
}

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

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

void func(){
	char table[110][110] ;
	
	for( int i=0 ; i<102 ; i++ ){
		for( int j=0 ; j<102 ; j++ ){
			if( i>=100-N+1 && i<=100 && j>=1 && j<=N ) table[i][j] = '#' ;
			else table[i][j] = ' ' ;
		}
	}
	
	int x = 1   ;
	int y = 100 ;
	int k = 0 ;
	bool f = true ;
	
	while(1){
		if( table[y+dy[k%4]][x+dx[k%4]] == ' ' ) break ;
		bool b = false ;
		while( table[y+dy[k%4]][x+dx[k%4]] != ' ' ){
			if( f || b ) table[y+dy[(k+1)%4]][x+dx[(k+1)%4]] = ' ' ;
			if( !b ) b = true  ;
			if(  f ) f = false ;
			x += dx[k%4] ;
			y += dy[k%4] ;
		}
		k++ ;
	}
	
	for( int i=100-N+1 ; i<=100 ; i++ ){
		for( int j=1 ; j<=N ; j++ ){
			cout << table[i][j] ;
		}
		cout << endl ;
	}
}

int main(){
	
	cin >> d ;
	while( d-- ){
		cin >> N ;
		func() ;
		if( d ) cout << endl ;
	}
	
return 0;
}