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
		len := 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++
				len = 1
			} else if out[nrow+dy[dir%4]][ncol+dx[dir%4]]=="#" {
				if len < 3 {
					break
				}
				dir++
				len = 1
			} else {
				row=nrow
				col=ncol
				out[row][col]="#"
				len++
			}
		}
		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):
    if n < 5:
        return

    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:])

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)


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]],
]


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


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

    while True:

        left, center, right = 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] == EXIST or area[end2.x][end2.y] == EXIST:
            return area
        elif area[offset.x][offset.y] == NOTHING and area[offset2.x][offset2.y] != EXIST:
            point.move(center)
            area[point.x][point.y] = EXIST
        else:
            move_index += 1
            move_index %= 4


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

    while True:

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

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

            move_index += 1
            move_index %= 4


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


output = []

for _ in range(int(input())):
    size = int(input())

    area = create_area(size)
    point = Vector(size - 1 + 2, 2)

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

    output.append(formater(result))

print("\n\n".join(output))

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)


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]],
]


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


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

    while True:

        left, center, right = 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] == EXIST or area[end2.x][end2.y] == EXIST:
            return area
        elif area[offset.x][offset.y] == NOTHING and area[offset2.x][offset2.y] != EXIST:
            point.move(center)
            area[point.x][point.y] = EXIST
        else:
            move_index += 1
            move_index %= 4


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

    while True:

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

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

            move_index += 1
            move_index %= 4


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


for _ in range(int(input())):
    size = int(input())

    area = create_area(size)
    point = Vector(size - 1 + 2, 2)

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

    print(output(result))