  ar=$stdin.read.split("\n")
  (ar.size-1).times do |n|
    h,w=ar[n].split.map(&:to_i)
    h.times do |i|
      print (i==0 || i==h-1) ? "#"*w + "\n" : "#" + "."*(w-2) + "#\n"
    end
    print "\n"
  end
