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.Printf("##\n# \n")
			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 <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;
    rep(i,in)rep(j,in)maze[i][j] = ' ';
    solve(in);

    if(!time)cout<<endl;
  }
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

main(){
  int n;
  char data[100][100];
  int dx[] = {0, 1, 0, -1};
  int dy[] = {-1, 0, 1, 0};
  int t;
  while(cin >> t){
    for(int tc=0;tc<t;tc++){
      cin >> n;
      if(tc != 0) cout << endl;
      if(n == 1){
	cout << "#" << endl;
	continue;
      }
      int y = n-1;
      int x = 0;
      fill(data[0], data[100], ' ');
      data[y][x] = '#';
      int d = 0;
      while(1){
	int ty = y + dy[d];
	int tx = x + dx[d];
	if(ty<0 || ty>=n){ d = (d+1)%4; continue; }
	if(tx<0 || tx>=n){ d = (d+1)%4; continue; }
	if(data[ty][tx] == '#') break;
	int tty = ty + dy[d];
	int ttx = tx + dx[d];
	if((tty>=0 || tty<n) && (ttx>=0 || ttx<n)){
	  if(data[tty][ttx] == '#'){
	    d = (d+1)%4; 
	    continue; 
	  }
	}
	int cnt = 0;
	for(int i=0;i<4;i++){
	  int tty = ty + dy[i];
	  int ttx = tx + dx[i];
	  if(tty<0 || tty>=n) continue;
	  if(ttx<0 || ttx>=n) continue;
	  if(data[tty][ttx] == '#') cnt++;
	}
	if(cnt > 1) break;
	data[ty][tx] = '#';
	y = ty;
	x = tx;
      }
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  cout << data[i][j];
	}
	cout << endl;
      }
    }
  }
  return 0;
}

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

using namespace std;

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

int main(void){
  int d;
  cin >> d;

  for(int i=0;i<d;i++){
    int n;
    cin >> n;
    bool sharp[n+4][n+4];

    memset(sharp,false,sizeof(sharp));

    int x=n+1,y=2;
    int vec=0;
    int cnt=0;
    if(i) cout << endl;

    while(1){
      sharp[x][y] = true;
      if(sharp[x+dx[vec]*2][y+dy[vec]*2] == true ||
	 (x+dx[vec]*2 == 0 || x+dx[vec]*2 == n+3) || 
	 (y+dy[vec]*2 == 0 || y+dy[vec]*2 == n+3)){
	vec = (vec+1)%4;
	if(cnt < 2) break;
	cnt = 0;
      }else{
	x += dx[vec];
	y += dy[vec];
	cnt++;
      }
    }

    for(int p=2;p<n+2;p++){
      for(int q=2;q<n+2;q++){
	if(sharp[p][q]){
	  cout << "#";
	}else{
	  cout << " ";
	}
      }
      cout << endl;
    }
  }
}

C++: #include <stdio.h>

#define N 100

int main(void){
    int dx[] = {0,1,0,-1};
    int dy[] = {-1,0,1,0};
    int map[N+2][N+2];
    int datas,d,dd,n;
    int x,y;
    
    scanf("%d", &datas);
    for (int i=0; i<datas; i++){
        // get size
        scanf("%d", &n);
        // reset map
        for (int xx=0; xx<n+2; xx++){
            for (int yy=0; yy<n+2; yy++){
                if (xx==0 || xx==n+1 || yy==0 || yy==n+1){
                    map[xx][yy]=-1;
                }else {
                    map[xx][yy]=0;
                }
            }
        }
        x=1; y=n; d=0; dd=1;
        // set spiral
        while(1){
            map[x][y]=1;
            if (map[x+dx[d]][y+dy[d]]==0){
                map[x+dx[dd]][y+dy[dd]]=-1;
            } else{
                if (map[x+dx[dd]][y+dy[dd]]==-1){
                    break;
                }else{
                    d = (d+1)%4;
                    dd = (dd+1)%4;
                }
            }
            x += dx[d];
            y += dy[d];
        }
        // output
        for (int yy=1; yy<=n; yy++){
            for (int xx=1; xx<=n; xx++){
                printf(map[xx][yy]==1?"#":" ");
            }
            printf("\n");
        }
        if (i<datas-1) printf("\n");
    }
    
    return 0;
}

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

const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
string g[102][100];

void init() {
  g[1][0] = "#";
  g[2][0] = "##";
  g[2][1] = "# ";
  for(int k = 3; k <= 100; ++k) {
    for(int i = 0; i < k-2; ++i) {
      g[k][i] = g[k-2][i];
    }
    for(int i = 0; i < k-2; ++i) {
      g[k][i] += " #";
    }
    g[k][k-2] = string(k, ' ');
    g[k][k-2][0] = g[k][k-2][k-1] = '#';
    g[k][k-1] = string(k, '#');
    for(int i = 0; i < k; ++i) {
      for(int j = 0; j < k; ++j) {
        if(make_pair(i,j) < make_pair(k-i-1,k-j-1)) {
          swap(g[k][i][j], g[k][k-i-1][k-j-1]);
        }
      }
    }
  }
}

int main() {
  init();
  int d;
  cin >> d;
  for(int tc = 0; tc < d; ++tc) {
    int n;
    cin >> n;
    if(tc) cout << endl;
    for(int i = 0; i < n; ++i) {
      cout << g[n][i] << endl;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define N 100
using namespace std;

int main(){
  int t,n,y,x,d,f;
  char c[N][N];
  int dy[4]={1,0,-1,0};
  int dx[4]={0,1,0,-1};
  cin>>t;
  while(t--){
    cin>>n;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)c[i][j]=' ';
    y=x=d=0;
    c[y][x]='#';
    while(1){
      int ny=y+dy[d];
      int nx=x+dx[d];
      f=0;
      if(ny<0||nx<0||n<=ny||n<=nx)f=1;
      if(c[ny+dy[d]][nx+dx[d]]=='#')f=1;
      if(f)d=(d+1)%4;
      ny=y+dy[d];
      nx=x+dx[d];
      if(c[ny+dy[d]][nx+dx[d]]=='#')break;
      if(c[ny+dy[(d+1)%4]][nx+dx[(d+1)%4]]=='#')break;
      y+=dy[d];
      x+=dx[d];
      c[y][x]='#';
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)cout<<c[i][j];
      cout<<endl;
    }
  }
  return 0;
}