p00891 Where's Wally
Do you know the famous series of children's books named "Where's Wally"? Each of the books contains a variety of pictures of hundreds of people. Readers are challenged to find a person called Wally in the crowd.

We can consider "Where's Wally" as a kind of pattern matching of two-dimensional graphical images. Wally's figure is to be looked for in the picture. It would be interesting to write a computer program to solve "Where's Wally", but this is not an easy task since Wally in the pictures may be slightly different in his appearances. We give up the idea, and make the problem much easier to solve. You are requested to solve an easier version of the graphical pattern matching problem.

An image and a pattern are given. Both are rectangular matrices of bits (in fact, the pattern is always square-shaped). 0 means white, and 1 black. The problem here is to count the number of occurrences of the pattern in the image, i.e. the number of squares in the image exactly matching the pattern. Patterns appearing rotated by any multiples of 90 degrees and/or turned over forming a mirror image should also be taken into account.



Input

The input is a sequence of datasets each in the following format.

w h p
image data
pattern data


The first line of a dataset consists of three positive integers w, h and p. w is the width of the image and h is the height of the image. Both are counted in numbers of bits. p is the width and height of the pattern. The pattern is always square-shaped. You may assume 1 ≤ w ≤ 1000, 1 ≤ h ≤ 1000, and 1 ≤ p ≤ 100.

The following h lines give the image. Each line consists of ⌈w/6⌉ (which is equal to &⌊(w+5)/6⌋) characters, and corresponds to a horizontal line of the image. Each of these characters represents six bits on the image line, from left to right, in a variant of the BASE64 encoding format. The encoding rule is given in the following table. The most significant bit of the value in the table corresponds to the leftmost bit in the image. The last character may also represent a few bits beyond the width of the image; these bits should be ignored.

character| value (six bits)
---|---
A-Z| 0-25
a-z| 26-51
0-9| 52-61
+| 62
/| 63

The last p lines give the pattern. Each line consists of ⌈p/6⌉ characters, and is encoded in the same way as the image.

A line containing three zeros indicates the end of the input. The total size of the input does not exceed two megabytes.

Output

For each dataset in the input, one line containing the number of matched squares in the image should be output. An output line should not contain extra characters.

Two or more matching squares may be mutually overlapping. In such a case, they are counted separately. On the other hand, a single square is never counted twice or more, even if it matches both the original pattern and its rotation, for example.

Example

Input

48 3 3
gAY4I4wA
gIIgIIgg
w4IAYAg4
g
g
w
153 3 3
kkkkkkkkkkkkkkkkkkkkkkkkkg
SSSSSSSSSSSSSSSSSSSSSSSSSQ
JJJJJJJJJJJJJJJJJJJJJJJJJI
g
Q
I
1 1 2
A
A
A
384 3 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/A
CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/AB
A
A
0 0 0


Output

8
51
0
98
```python
import string
import sys

S = string.ascii_uppercase + string.ascii_lowercase + string.digits + "+/"

mod = 10**9 + 9; p = 13; q = 19
L = 1000
p_table = [1]*(L+1); q_table = [1]*(L+1)
for i in range(L):
    p_table[i+1] = p_table[i] * p % mod
    q_table[i+1] = q_table[i] * q % mod
readline = sys.stdin.readline
write = sys.stdout.write
def to_hash(S, W, H):
    D = [[0]*(W+1) for i in range(H+1)]
    for i in range(H):
        su = 0
        dp = D[i]
        di = D[i+1]
        si = S[i]
        for j in range(W):
            su = (su*p + si[j]) % mod
            di[j+1] = (su + dp[j+1]*q) % mod
    return D
mod = 10**9 + 9; p = 13; q = 19
def get(S, x0, y0, x1, y1):
    P = p_table[x1 - x0]; Q = q_table[y1 - y0]
    return (S[y1][x1] - S[y1][x0] * P - S[y0][x1] * Q + S[y0][x0] * (P * Q) % mod) % mod
def rotate(S, W, H):
    T = [[0]*H for i in range(W)]
    for i in range(H):
        for j in range(W):
            T[j][H-1-i] = S[i][j]
    return T
def mirror(S, W, H):
    T = [[0]*W for i in range(H)]
    for i in range(H):
        for j in range(W):
            T[i][W-1-j] = S[i][j]
    return T


def solve():
    W, H, P = map(int, readline().split())
    if W == H == P == 0:
        return False
    D = S.index
    C = []
    for i in range(H):
        data = readline().strip()
        cs = []
        for c in data:
            v = D(c)
            for k in range(5, -1, -1):
                cs.append(v & (1 << k) > 0)
        C.append(cs)
    E = []
    for i in range(P):
        data = readline().strip()
        es = []
        for c in data:
            v = D(c)
            for k in range(5, -1, -1):
                es.append(v & (1 << k) > 0)
        E.append(es)
    E0 = E
    sv = set()
    for k in range(4):
        sv.add(to_hash(E, P, P)[-1][-1])
        E = rotate(E, P, P)
    E = mirror(E0, P, P)
    for k in range(4):
        sv.add(to_hash(E, P, P)[-1][-1])
        E = rotate(E, P, P)
    F = to_hash(C, W, H)
    ans = 0
    for i in range(H-P+1):
        for j in range(W-P+1):
            if get(F, j, i, j+P, i+P) in sv:
                ans += 1
    write("%d\n" % ans)
    return True
while solve():
    ...

```