#1291
Unrated
Baza
시간 제한
1s
메모리 제한
64MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Mirko got a summer internship in a big IT company. This company builds a large database consisting of N rows and M columns. On his first day, Mirko received a total of Q queries. Each query consists of M numbers. However, some numbers got lost during transition, so they are denoted with -1. Mirko wants to know how many rows of the database correspond to the query, i.e., how many rows of the database have identical numbers as the query, excluding -1. For example, if the query is in the form of -1 3 2, then we need to count the rows of the database that have any number in the first column, have the number 3 in the second column, and have the number 2 in the third column. Since he just started with his internship, Mirko needs your help. Help him and answer the queries!

입력

The first line of input contains N (1 ≤ N ≤ 10310^{3}) and M (1 ≤ M ≤ 10310^{3}), the size of the database. Each of the following N lines contains M numbers AijA_{ij} (1 ≤ AijA_{ij}10610^{6}), the content of the database. The following line contains Q (1 ≤ Q ≤ 50), the number of queries. Each of the following Q lines contains M numbers BijB_{ij} (BijB_{ij} = -1 or 1 ≤ BijB_{ij}10610^{6}), the description of the i-th query.

출력

The output must contain Q lines, each line containing X, the answer to the i-th query from the task.

예제 입력 1

4 3
1 5 2
2 3 4
4 3 2
5 4 6
3
-1 -1 2
-1 3 2
-1 -1 -1

예제 출력 1

2
1
4

예제 입력 2

3 8
6 5 97 99 82 50 95 1
85 62 11 64 94 84 88 19
43 99 11 64 94 84 31 19
3
-1 -1 11 64 94 84 -1 19
-1 -1 -1 99 -1 -1 -1 1
95 -1 -1 -1 -1 80 -1 -1

예제 출력 2

2
1
0
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.