https://www.nowcoder.com/acm/contest/170/B
var
a:array[1..300,1..300]of char;
f:array[1..300]of string;
n,m,q,i,j,len,minp,x,y:longint;
begin
readln(n,m,q);
for i:=1 to n do
begin
for j:=1 to m do
read(a[i,j]);
readln;
end;
for i:=1 to q do
begin
readln(x,y);
len:=0;
f[1]:='';
while (x+len<=n)and(y+len<=m) do
begin
f[1]:=f[1]+a[x+len,y+len];
inc(len);
end;
for j:=2 to len do
begin
f[j]:=f[j-1]+f[j-1][1];
delete(f[j],1,1);
end;
minp:=1;
for j:=2 to len do
if f[j]<f[minp] then
minp:=j;
writeln(f[minp]);
end;
end.