procedure main()
   every print([q(1),q(2),q(3),q(4),q(5),q(6),q(7),q(8)])
end

procedure q(r)
   suspend place(1 to 8,r)
end

procedure place(c,r)
   static up, down, col
   initial {
      up := list(15,0)
      down := list(15,0)
      col := list(8,0)
      }
   if col[c] = up[8 + r - c] = down[r + c - 1] = 0
   then suspend col[c] <- up[8 + r - c] <-
      down[r + c - 1] <- c
end

procedure print(a)
   static line, bar
   initial {
      line := repl("+-",8) || "+"
      bar := repl("| ",8) || "|"
      }
   every bar[!a*2] <- "Q" do {
      write(line)
      write(bar)
      }
   write(line,"\n\n")
   return
end
