Micro has just joined internship in a big company. Here he has to test some problems. He has got his first problem but he has to go for his sister's marriage. So, he has asked you, a dear friend to him, to test the problem on his behalf . If you do so, he would get you a big gift and you'll definitely be getting a big party :)
The problem says:
You are given a matrix A of size m*n filled with positive integers. Now you are given q queries.
In each query:
You have to count how many integers from 1 to value are divisible by any of these k primes (don't count any number twice).
Finally for each query, you have to print the value and this count space separated in one line.
See the sample input/output and image for more clarity.
Now hurry up as the deadline is coming.
Input:
First line contains two integers m and n.
Then a matrix of size m*n is given as input.
Then number of queries q.
For each query, first line contains x1,y1,x2,y2. Second line contains k. Third line contains k distinct prime numbers.
Output:
For each query,in one line, you have to print the value obtained, then after a space, print count.
Constraints:
1<=m,n<=500
1<=A(i,j)<=10^9
1<=q<=18000
0<=x1,x2<=m-1
0<=y1,y2<=n-1
1<=k<=10
k distinct prime numbers ; each prime number<=61
All the inputs are integers
In the first query,
The red matrix in the left is L1 and the red matrix in the right is R1.
The blue matrix in the left is L2 and the blue matrix in the right is R2.
overlapping region of L1 and L2 contains only one element as 1
overlapping region of R1 and R2 contains only one element as 16
value=1+16=17
primes={2,3,5}
numbers divisible by 2 in {1,2,3,....,15,16,17}={2,4,6,8,10,12,14,16}
numbers divisible by 3 in {1,2,3,....,15,16,17}={3,6,9,12,15}
numbers divisible by 5 in {1,2,3,....,15,16,17}={5,10,15}
numbers divisible any of 2,3 or 5={2,3,4,5,6,8,9,10,12,14,15,16}
so count=12
hence output: 17 12