d = gets.to_i
d.times do |i|
    n = gets.to_i
    a = Array.new(n).map { Array.new(n, 0) }
    a.map! {|r| [9] + r + [9]}
    a.unshift [9] * (n + 2)
    a<< [9] * (n + 2)
    y = n
    x = 1
    dy = -1
    dx = 0
    loop do
        a[y][x] = 1
        if a[y + dy][x + dx] == 0
            a[y + dx][x - dy] = 9
            y += dy
            x += dx
        else
            dy, dx = dx, -dy
            if a[y + dy][x + dx] == 0
                a[y - dx][x + dy] = 9
                y += dy
                x += dx
            else
                break
            end
        end
    end
    a[1..-2].each do |r|
        puts r.map {|x| x == 1 ? '#' : ' '} * ''
    end
    puts if i < d - 1
end

