import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
{
Paiza.getInstance().resolve(new MyResolver());
}
}
{
@Override
public int resolve(Paiza.Widget widget) {
int count = 0;
for (int y = 0; y < home.getH(); y++) {
for (int x = 0; x < home.getW(); x++) {
boolean flag = true;
for (int dy = 0; flag && dy < widget.getS(); dy++) {
for (int dx = 0; flag && dx < widget.getT(); dx++) {
if (home.isSpace(x + dx, y + dy) == false) {
flag = false;
}
}
}
if (flag) {
count++;
}
}
}
return count;
}
}
{
protected Paiza.Home home;
public void setHome(Paiza.Home home) {
this.home = home;
}
public abstract int resolve(Paiza.Widget widget);
}
final class Paiza
{
private static Paiza paiza = null;
private Home home;
private ArrayList<Widget> widgets;
String[] hw
= in.
readLine().
split(" "); for (int y = 0; y < home.getH(); y++) {
for (int x = 0; x < home.getW(); x++) {
home.setDisplay(x, y, (int)(line.charAt(x) - '0'));
}
}
int N
= Integer.
parseInt(in.
readLine()); widgets = new ArrayList<Widget>(N);
for (int i = 0; i< N; i++) {
String[] st
= in.
readLine().
split(" "); widgets.
add(new Widget
(Integer.
parseInt(st
[0]),
Integer.
parseInt(st
[1]))); }
}
private void answer(int count) {
}
public void resolve
(Resolver resolver
) { resolver.setHome(home);
for (Widget widget : widgets) {
int count = resolver.resolve(widget);
answer(count);
}
}
public static Paiza getInstance
() throws java.
lang.
Exception { if (paiza == null) {
paiza = new Paiza();
}
return paiza;
}
public final class Home
{
private final int H;
private final int W;
private int[][] display;
private Home(int H, int W) {
this.H = H;
this.W = W;
display = new int[H][W];
}
private void setDisplay
(int x,
int y,
int e
) throws java.
lang.
Exception { if (x < 0 || x >= W) {
}
if (y < 0 || y >= H) {
}
if (e != 0 && e != 1) {
}
display[y][x] = e;
}
public int getH() {
return H;
}
public int getW() {
return W;
}
public boolean isSpace(int x, int y) {
if (x < 0 || y < 0 || x >= W || y >= H) {
return false;
}
return display[y][x] == 0;
}
}
public final class Widget
{
private final int s;
private final int t;
private Widget(int s, int t) {
this.s = s;
this.t =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