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()
		}
	}
}

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0141

"""
import sys
from sys import stdin
input = stdin.readline
from itertools import cycle


def guruguru(n):
    line = 0
    dirs = cycle([(0, -1), (1, 0), (0, 1), (-1, 0)])

    M = [[' '] * n for _ in range(n)]
    cx = 0
    cy = n - 1

    while line < n:
        line += 1
        dx, dy = dirs.__next__()
        while True:
            M[cy][cx] = '#'
            nx = cx + dx
            ny = cy + dy
            nnx = nx + dx
            nny = ny + dy

            if nx < 0 or nx >= n:
                break
            if ny < 0 or ny >= n:
                break
            if nny < 0 or nny >= n or nnx < 0 or nnx >= n:
                pass
            else:
                if M[nny][nnx] != ' ':
                    break
            cx = nx
            cy = ny

    for l in M:
        print(''.join(map(str, l)))


def main(args):
    n = int(input())
    for i in range(n):
        size = int(input())
        guruguru(size)
        if i != (n - 1):
            print()


if __name__ == '__main__':
    main(sys.argv[1:])

Python: vector = ((0, -1), (1, 0), (0, 1), (-1, 0))

def make_guruguru(d):
  lst = [["#"] * (d + 4)]
  for _ in range(d + 2):
    lst.append(["#"] + [" "] * (d + 2) + ["#"])
  lst.append(["#"] * (d + 4))
  x, y = 2, d + 1
  lst[y][x] = "#"
  direct = 0
  vx, vy = vector[0]
  cnt = 1
  while True:
    while lst[y + vy * 2][x + vx * 2] == " ":
      lst[y + vy][x + vx] = "#"
      y += vy
      x += vx
      cnt += 1
    if cnt <= 1:
      break
    direct = (direct + 1) % 4
    vx, vy = vector[direct]
    cnt = 0
  for y in range(2, d + 2):
    print("".join(lst[y][2:-2]))
  print()
  for line in lst:
    print("".join(line))

n = int(input())
for _ in range(n):
  d = int(input())
  make_guruguru(d)

Python: # AOJ 0141 Spiral Pattern
# Python3 2018.6.23 bal4u

for ci in range(int(input())):
	if ci > 0: print()
	n = int(input())
	a = [[' ' for c in range(n+5)] for c in range(n+5)]
	for r in range(0, n+4, n+3):
		for c in range(n+4): a[r][c] = '#'
	for c in range(0, n+4, n+3):
		for r in range(n+4): a[r][c] = '#'
	r, c = n+1, 2
	a[r][c] = '#'
	d = 'U'
	stop = 0
	while 1:
		if stop >= 4: break
		if d == 'U':
			if a[r-2][c] == '#' or a[r-1][c] == '#' or a[r-1][c+1] == '#':
				d = 'R'
				stop += 1
			else:
				r -= 1
				a[r][c] = '#'
				stop = 0
		if d == 'R':
			if a[r][c+2] == '#' or a[r][c+1] == '#' or a[r+1][c+1] == '#':
				d = 'D'
				stop += 1
			else:
				c += 1
				a[r][c] = '#'
				stop = 0
		if d == 'D':
			if a[r+2][c] == '#' or a[r+1][c] == '#' or a[r+1][c-1] == '#':
				d = 'L'
				stop += 1
			else:
				r += 1
				a[r][c] = '#'
				stop = 0
		if d == 'L':
			if a[r][c-2] == '#' or a[r][c-1] == '#' or a[r-1][c-1] == '#':
				d = 'U'
				stop += 1
			else:
				c -= 1
				a[r][c] = '#'
				stop = 0
	for r in range(2, n+2):	print(*a[r][2:n+2], sep='')

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0141

"""
import sys
from sys import stdin
input = stdin.readline
from itertools import cycle


def guruguru(n):
    dirs = cycle([(0, -1), (1, 0), (0, 1), (-1, 0)]) #  x, y???????????? (???????????????????????????)

    M = [[' '] * n for _ in range(n)] #  ??????????????¨?????????????????§?????????
    cx = 0                      #  ??????????????°???
    cy = n - 1
    line = 0                    #  ???????????§??????????????????n??¨???????????°??????????????¨??????

    while line < n:
        line += 1
        dx, dy = dirs.__next__() #  ???????????????????????????????????????????????????
        while True:
            M[cy][cx] = '#'

            nx = cx + dx        #  ?¬???????????????¨???????????????
            ny = cy + dy
            if not 0 <= nx < n: #  ??????????????????????????????????????§???????????¢?????????
                break
            if not 0 <= ny < n:
                break
            nnx = nx + dx       #  ?¬?????¬???????????????¨???????????????
            nny = ny + dy
            if 0 <= nny < n and 0 <= nnx < n:
                if M[nny][nnx] != ' ': #  ??????????????????????????????????????¢??????????????????????????£??????????????´??????????????¢?????????
                    break
            cx = nx
            cy = ny

    # ?????????????????????????????????
    for l in M:
        print(''.join(l))


def main(args):
    n = int(input())
    for i in range(n):
        size = int(input())
        guruguru(size)
        if i != (n - 1):        #  ????????\?????????????????????????????????????????\??????
            print()


if __name__ == '__main__':
    main(sys.argv[1:])

Python: dd = ((-1, 0), (0, -1), (1, 0), (0, 1))

d = int(input())
for i in range(d):
    if i:
        print()
    N = int(input())
    MP = [[" "]*N for i in range(N)]
    for i in range(N):
        MP[i][0] = "#"
    def walk(x, y, d, n):
        dx, dy = dd[d % 4]
        for k in range(n):
            x += dx; y += dy
            MP[y][x] = "#"
        return x, y
    x = y = 0
    r = N-1; d = 2
    while r > 1:
        x, y = walk(x, y, d, r)
        x, y = walk(x, y, d+1, r)
        r -= 2; d += 2
    if r == 1:
        walk(x, y, d, r)
    for line in MP:
        print(*line, sep='')