### constant

MAX_INT = (1 << 31) - 1

### main

loop do
  r, c, q = gets.split.map(&:to_i)
  break if (r | c | q) == 0

  mtx = r.times.map{gets.split.map(&:to_i)}
  #p mtx

  q.times do
    r0, c0, r1, c1 = gets.split.map(&:to_i)
    #p [r0, c0, r1, c1]

    min_g = MAX_INT

    for r in (r0..r1)
      gs = mtx[r]
      for c in (c0..c1)
        g = gs[c]
        min_g = g if min_g > g
      end
    end

    puts min_g
  end
end