h, w, k, p = gets.split.map &:to_i m = {} f = k.times.map do |i| x, y, n = gets.split m[33 * x.to_i + y.to_i] = i n end comb = [*0...k].combination(p).to_a ans = [0, []] comb.each do |arr| a = [] (h+1).times do |_h| a << [] (w+1).times do |_w| if _h == 0 && _w == 0 a[_h][_w] = 1 next end i = m[33 * _h + _w] if i && !arr.index(i) a[_h][_w] = 0 next end if _h == 0 a[_h][_w] = a[_h][_w-1] next end if _w == 0 a[_h][_w] = a[_h-1][_w] next end a[_h][_w] = a[_h-1][_w] + a[_h][_w-1] end end if ans[0] < a[h][w] ans = [a[h][w], arr] end end puts ans[0] % (10**9+7) ans[1].each{|i| puts f[i]}