/* paiza POH! vol.2
* result:
* http://p...content-available-to-author-only...a.jp/poh/paizen/result/0bf10df52c3155b2048dd41ef28f648a
* author: Leonardone @ NEETSDKASU
*/
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
{
String[] hw
= in.
readLine().
split(" "); final int H
= Integer.
parseInt(hw
[0]); // ホーム画面縦の区画数 final int W
= Integer.
parseInt(hw
[1]); // ホーム画面横の区画数
int[][] home = new int[H][W];
int[][] hoge = new int[H][W];
int spacecount = 0;
for (int y = 0; y < H; y++)
{
int count = 0;
for (int x = 0; x < W; x++)
{
int tx = W - x - 1;
char ch = line.charAt(tx);
if (ch == '0')
{
spacecount++;
count++;
if (y > 0)
{
hoge[y][tx] = hoge[y - 1][tx] + 1;
}
else
{
hoge[y][tx] = hoge[y][tx] = 1;
}
}
else
{
count = 0;
hoge[y][tx] = 0;
}
home[y][tx] = count;
}
}
final int N
= Integer.
parseInt(in.
readLine()); // ウィジェット数
int[][] result = new int[300][300];
for (int i = 0; i < N; i++)
{
String[] st
= in.
readLine().
split(" "); int s
= Integer.
parseInt(st
[0]); // ウィジェットの縦サイズ int t
= Integer.
parseInt(st
[1]); // ウィジェットの横サイズ
if (s > H || t > W)
{
continue;
}
if (result[s][t] > 0)
{
System.
out.
println(result
[s
][t
] - 1); continue;
}
if (s == 1 && t == 1)
{
System.
out.
println(spacecount
); continue;
}
int count = 0;
if (W > H)
{
for (int hy = H - 1; hy >= s - 1; hy--)
{
for (int hx = 0; hx < W - t + 1; hx++)
{
if (home[hy][hx] < t)
{
hx += home[hy][hx];
continue;
}
if (hoge[hy][hx] < s)
{
continue;
}
int dy;
for (dy = 1; dy < s; dy++)
{
int y = hy - dy;
if (y >= H)
{
break;
}
if (home[y][hx] < t)
{
break;
}
}
if (dy == s)
{
count++;
}
}
}
}
else
{
for (int hx = 0; hx < W - t + 1; hx++)
{
for (int hy = H - 1; hy >= s - 1; hy--)
{
if (home[hy][hx] < t)
{
continue;
}
if (hoge[hy][hx] < s)
{
hy -= hoge[hy][hx];
continue;
}
int dy;
for (dy = 1; dy < s; dy++)
{
int y = hy - dy;
if (y >= H)
{
break;
}
if (home[y][hx] < t)
{
break;
}
}
if (dy == s)
{
count++;
}
}
}
}
result[s][t] = count + 1;
}
} // end of main(String[])
}