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<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)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>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int m,n,x,y,p,xx,yy,d;
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
main(){
  cin>>m;
  while(m--){
    cin>>n;
    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){
        y=dy[i]+yy,x=dx[i]+xx;
        if(y<0||y>=n||x<0||x>=n)c++;
        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;
      }
    }
    r(i,n)cout<<s[i]<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
 
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
 
void pp(vector<vi> &v){
    rep(i, v.size()){
        rep(j, v.size()){
            cout << v[i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
}
 
bool check(vector<vi> &v, int nx, int ny, int revdir){
    rep(i, 4){
        if(revdir == i) continue;
        int x = nx+dx[i];
        int y = ny+dy[i];
        if(v[y][x] == 1) return false;
    }
    return true;
}
 
int main(){
    int d;
    cin >> d;
    rep(k, d){
        if(k)cout << endl;
        int n;
        cin >> n;
        vector<vi> v(n+4, vi(n+4, 0));
        rep(i, n+4) rep(j, n+4) if(i == 0 || i == n+3 || j == 0 || j == n+3) v[i][j] = 1;
        int x = 2;
        int y = n+3-2;
        int dir = 0;
        v[y][x] = 1;
 
        bool end = false;
        while(1){
            int nx = x+dx[dir];
            int ny = y+dy[dir];
            if(check(v, nx, ny, (dir+2)%4)){
                v[ny][nx] = 1;
                x = nx, y = ny;
                end = false;
            }else{
                dir = (dir+1)%4;
                if(end) break;
                end = true;
            }
        }
 
        //pp(v);
        for(int i = 2; i < n+2; i++){
            for(int j = 2; j < n+2; j++){
                cout << (v[i][j]?'#':' ');
            }
            cout << endl;
        }
    }
 
    return 0;
}

C++: #include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(void)
{
  int a[10]={};
  int i=0;
  int j=0;

  for(i=0;i<10;i++)
    cin>>a[i];

  sort(a,a+10);

  cout<<a[9]<<endl<<a[8]<<endl<<a[7]<<endl;

}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

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

void pp(vector<vi> &v){
	rep(i, v.size()){
		rep(j, v.size()){
			cout << v[i][j] << ' ';
		}
		cout << endl;
	}
	cout << endl;
}

bool check(vector<vi> &v, int nx, int ny, int revdir){
	rep(i, 4){
		if(revdir == i) continue;
		int x = nx+dx[i];
		int y = ny+dy[i];
		if(v[y][x] == 1) return false;
	}
	return true;
}

int main(){
	int d;
	cin >> d;
	while(d--){
		int n;
		cin >> n;
		vector<vi> v(n+4, vi(n+4, 0));
		rep(i, n+4) rep(j, n+4) if(i == 0 || i == n+3 || j == 0 || j == n+3) v[i][j] = 1;
		int x = 2;
		int y = n+3-2;
		int dir = 0;
		v[y][x] = 1;

		bool end = false;
		while(1){
			int nx = x+dx[dir];
			int ny = y+dy[dir];
			if(check(v, nx, ny, (dir+2)%4)){
				v[ny][nx] = 1;
				x = nx, y = ny;
				end = false;
			}else{
				dir = (dir+1)%4;
				if(end) break;
				end = true;
			}
		}

		//pp(v);
		for(int i = 2; i < n+2; i++){
			for(int j = 2; j < n+2; j++){
				cout << (v[i][j]?'#':' ');
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

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;
      }
      cout << endl;
    }
  }
  return 0;
}