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.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: class Vector:

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def move(self, offset):
        self.x += offset[0]
        self.y += offset[1]

    def move_offset(self, offset, multiple=1):
        x = self.x + offset[0] * multiple
        y = self.y + offset[1] * multiple
        return Vector(x, y)


class Pattern:
    NOTHING = " "
    EXIST = "#"
    SENTINEL = "?"

    MOVE = [
        [[-1, -1], [-1, +0], [-1, +1]],
        [[-1, +1], [-0, +1], [+1, +1]],
        [[+1, +1], [+1, +0], [+1, -1]],
        [[+1, -1], [+0, -1], [-1, -1]],
    ]

    @classmethod
    def create_area(cls, size):
        area = [[cls.SENTINEL] * 2 + [cls.NOTHING] * size + [cls.SENTINEL] * 2 for _ in range(size)]
        tmp = [[cls.SENTINEL] * size + [cls.SENTINEL] * 2 * 2]
        area = tmp * 2 + area + tmp * 2
        return area

    @classmethod
    def even_spiral_pattern(cls, area, point):
        move_index = 0
        area[point.x][point.y] = cls.EXIST

        while True:

            left, center, right = cls.MOVE[move_index]
            end1, end2 = point.move_offset(left), point.move_offset(right)
            offset, offset2 = point.move_offset(center), point.move_offset(center, 2)

            if area[end1.x][end1.y] == cls.EXIST or area[end2.x][end2.y] == cls.EXIST:
                return area
            elif area[offset.x][offset.y] == cls.NOTHING and area[offset2.x][offset2.y] != cls.EXIST:
                point.move(center)
                area[point.x][point.y] = cls.EXIST
            else:
                move_index += 1
                move_index %= 4

    @classmethod
    def odd_spiral_pattern(cls, area, point):
        move_index = 0
        is_end = False
        area[point.x][point.y] = cls.EXIST

        while True:

            left, center, right = cls.MOVE[move_index]
            offset, offset2 = point.move_offset(center), point.move_offset(center, 2)

            if area[offset.x][offset.y] == cls.NOTHING and area[offset2.x][offset2.y] != cls.EXIST:
                point.move(center)
                area[point.x][point.y] = cls.EXIST
                is_end = False
            else:
                if is_end:
                    return area
                else:
                    is_end = True

                move_index += 1
                move_index %= 4

    @classmethod
    def formater(cls, area):
        output = ["".join(item).replace(cls.SENTINEL, "") for item in area[2:-2]]
        output = "\n".join(output)
        return output

    @classmethod
    def solve(cls, size):
        area = cls.create_area(size)
        point = Vector(size - 1 + 2, 2)

        if size % 2 == 0:
            result = cls.even_spiral_pattern(area, point)
        else:
            result = cls.odd_spiral_pattern(area, point)

        return cls.formater(result)


sizes = [int(input()) for _ in range(int(input()))]
results = [Pattern.solve(num) for num in sizes]
print("\n\n".join(results))

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

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


M = []
def guruguru(n):
    global M
    dirs = [(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:
        dx, dy = dirs[line % 4]
        line += 1
        while True:
            M[cy][cx] = '#'

            nx = cx + dx        #  ?¬???????????????¨???????????????
            if not 0 <= nx < n: #  ??????????????????????????????????????§???????????¢?????????
                break
            ny = cy + dy
            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: 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]))

n = int(input())
make_guruguru(int(input()))
for _ in range(n - 1):
  print()
  make_guruguru(int(input()))

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 _ in range(n):
        size = int(input())
        guruguru(size)


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