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 <string>
using namespace std;
int d;
string map[105];
int n;
 
void visit() {
  int dx[4] = {0,1,0,-1};
  int dy[4] = {-1,0,1,0};
  int sum,  flg = 0;
  int x = 2,y = n;
  map[y][x] = ' ';
  int ab[4] = {2,2,2,2};
 
  while(1) {
    sum = 0;
    while(1) {
      if(map[y+dy[flg]*2][x+dx[flg]*2] != '#' && map[y+dy[flg]][x+dx[flg]] != ' ' ) {
    flg++;
    //  cout << sum << endl;
 
    break;
      }
       
      map[y+dy[flg]][x+dx[flg]] = ' ';
      y = y + dy[flg];
      x = x + dx[flg];
      sum++;
    }
    if(flg == 4) flg = 0;
    if(sum == 0) break;
    ab[0] = ab[1];
    ab[1] = ab[2];
    ab[2]  = sum;
    if(ab[0] == 1 && ab[2] == 1 && ab[1] == 1) break;
 
  }
}
 
 
int main() {
   
  cin >> d;
   
  for(int l=0;l<d;l++) {
     
    cin >> n;
 
    if(n == 1) {
      cout << "#" <<endl  ;
    if(l != d-1) cout << endl;
    continue;
    }   
 
    for(int i=0;i<=n+1;i++){
      map[i].resize(n+2);
      for(int j=0;j<=n+1;j++){
    map[i][j] = '#';
    if(i == 0 || j == 0 || i == n+1 || j == n+1) map[i][j] = '.';
      }
    }
     
     
    visit();
     
    for(int i=1;i<=n;i++){
      for(int j=1;j<map[i].size()-1;j++) {
    cout << map[i][j];
      }
      cout << endl;
    }
    if(l != d-1) 
      cout << endl;
     
  }
return 0;
}

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

void spiral(int n);

int main(void){
  int d;
  cin>>d;
  int n;
  for(int i=0;i<d;i++){
    cin>>n;
    spiral(n);
    cout<<endl;
    if(i<d-1){
      cout<<endl;
    }
  }
  return 0;
}

void spiral(int n){
  int paper[n+4][n+4];
  for(int i=0;i<n+4;i++){
    for(int j=0;j<n+4;j++){
      paper[i][j]=0;
    }
  }
  for(int i=0;i<n+4;i++){
    paper[0][i]=1;
    paper[i][0]=1;
    paper[n+3][i]=1;
    paper[i][n+3]=1;
  }

  int now_x=2;
  int now_y=n+1;
  int forward=0;
  for(int _=0;_<n*n;_++){
    if(paper[now_y-1][now_x]+paper[now_y][now_x-1]+paper[now_y+1][now_x]+paper[now_y][now_x+1]<2){
      paper[now_y][now_x]=1;
    }
    if(forward==0){
      if(paper[now_y-2][now_x]==1){
        forward=1;
      }
      else{
        now_y-=1;
      }
    }
    else if(forward==1){
      if(paper[now_y][now_x+2]==1){
        forward=2;
      }
      else{
        now_x+=1;
      }
    }
    else if(forward==2){
      if(paper[now_y+2][now_x]==1){
        forward=3;
      }
      else{
        now_y+=1;
      }
    }
    else{
      if(paper[now_y][now_x-2]==1){
        forward=0;
      }
      else{
        now_x-=1;
      }
    }
  }

  for(int i=2;i<n+2;i++){
    for(int j=2;j<n+2;j++){
      if(paper[i][j]==1){
        cout<<"#";
      }
      else{
        cout<<" ";
      }
    }
    if(i<n+1){
      cout<<endl;
    }
  }
}

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

int main()
{
    int n, d;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> d;

        if( i >= 1 )
            cout << endl;

        if( d == 1 )
        {
            cout << "#" << endl;
            continue;
        }
        else if( d == 2 )
        {
            cout << "##" << endl;
            cout << "# " << endl;
            continue;
        }

        char a[d][d], cnt = 3;
        for( int j = 0; j < d; j++ )
            for( int k = 0; k < d; k++ )
                a[j][k] = ' ';

        for( int j = 0; j < d; j++ )
        {
            a[j][0] = '#';
            a[0][j] = '#';
            a[j][d-1] = '#';
        }

        int x = d - 1, y = d - 1;
        while( 1 )
        {
            if( cnt != d )
            {
                while( a[x][y-2] != '#' )
                {
                    a[x][y-1] = '#';
                    y--;
                }
                cnt++;
            }
            else
                break;

            if( cnt != d )
            {
                while( a[x-2][y] != '#' )
                {
                    a[x-1][y] = '#';
                    x--;
                }
                cnt++;
            }
            else
                break;

            if( cnt != d )
            {
                while( a[x][y+2] != '#' )
                {
                    a[x][y+1] = '#';
                    y++;
                }
                cnt++;
            }
            else
                break;

            if( cnt != d )
            {
                while( a[x+2][y] != '#' )
                {
                    a[x+1][y] = '#';
                    x++;
                }
                cnt++;
            }
            else
                break;            
        }
        for( int j = 0; j < d; j++ )
        {
            for( int k = 0; k < d; k++ )
                cout << a[j][k];
            cout << endl;
        }
    }
    return 0;
}

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

void draw(int n){
  int m[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
  int t=0, muki=0, x=n+1, y=2;
  int cn[n+4][n+4];
  for(int i=1; i<n+3; i++)
    for(int j=1; j<n+3; j++)
      cn[i][j]=0;
  for(int i=0; i<n+4; i++){
    cn[i][0]=1;
    cn[i][n+3]=1;
    cn[0][i]=1;
    cn[n+3][i]=1;
  }

  while(t<2){
    if(t==1){
      if(cn[x+m[muki%4][0]+m[(muki+1)%4][0]][y+m[muki%4][1]+m[(muki+1)%4][1]]==1)
	break;
    }
    if(cn[x+2*m[muki%4][0]][y+2*m[muki%4][1]]==1)
      {t++; muki++; cn[x][y]=1;}
    else{
      t = 0;
      cn[x][y]=1;
      x+=m[muki%4][0];
      y+=m[muki%4][1];
    }
  }
  
  for(int i=2; i<n+2; i++){
    for(int j=2; j<n+2; j++){
      if(cn[i][j]==1)
	cout << "#";
      else
	cout << " ";
    }
    cout << endl;
  }
}

int main(){
  int d, n;
  cin >> d;

  for(int i=0; i<d-1; i++){
    cin >> n;
    draw(n);
    cout << endl;
  }
  cin >> n;
  draw(n);
  return 0;
}