def f(w,h,x,y,cs)
return 0 if x<0 || w<=x || y<0 || h<=y
return cs[y][x]
end
def f2(w,h,n)
cs=[]
h.times{
cs<<[0]*w
}
n.times{
x,y=gets.split(" ").map{|e| e.to_i-1}
}
end
while true
w,h,n=gets.split(" ").map{|e| e.to_i}
break if w==0 && h==0
f2(w,h,n)
end
ZGVmIGYodyxoLHgseSxjcykKCXJldHVybiAwIGlmIHg8MCB8fCB3PD14IHx8IHk8MCB8fCBoPD15CglyZXR1cm4gY3NbeV1beF0KZW5kCmRlZiBmMih3LGgsbikKY3M9W10KaC50aW1lc3sKCWNzPDxbMF0qdwp9Cm4udGltZXN7Cgl4LHk9Z2V0cy5zcGxpdCgiICIpLm1hcHt8ZXwgZS50b19pLTF9Cn0KZW5kCgp3aGlsZSB0cnVlCncsaCxuPWdldHMuc3BsaXQoIiAiKS5tYXB7fGV8IGUudG9faX0KYnJlYWsgaWYgdz09MCAmJiBoPT0wCmYyKHcsaCxuKQplbmQ=