#include <cstdio>
#include <set>
using namespace std;
typedef unsigned long long ull;
int n, m, p;
char code[1010][1010];
bool ma[1010][1010];
bool pattern[1010][1010];

ull ha[1010][1010], tmp[1010][1010];
ull mh[1010][1010];
void compute_hash(bool a[1010][1010], int n, int m) {
    const ull B1 = 9983;
    const ull B2 = 100000007;
    ull t1 = 1;
    for (int j = 0; j < p; j++) t1 *= B1;

    for (int i = 0; i < n; i++) {
        ull e = 0;
        for (int j = 0; j < p; j++) e = e * B1 + a[i][j];

        for (int j = 0; j + p <= m; j++) {
            tmp[i][j] = e;
            if (j + p < m) e = e * B1 - t1 * a[i][j] + a[i][j + p];
        }
    }

    ull t2 = 1;
    for (int i = 0; i < p; i++) t2 *= B2;

    for (int j = 0; j + p <= m; j++) {
        ull e = 0;
        for (int i = 0; i < p; i++) e = e * B2 + tmp[i][j];

        for (int i = 0; i + p <= n; i++) {
            ha[i][j] = e;
            if (i + p < n) e = e * B2 - t2 * tmp[i][j] + tmp[i + p][j];
        }
    }
    
}

int getbit(char ch) {
    if (ch >= 'A' && ch <= 'Z')         return 0 + ch - 'A';
    if (ch >= 'a' && ch <= 'z')         return 26 + ch - 'a';
    if (ch >= '0' && ch <= '9')         return 52 + ch - '0';
    if (ch == '+') return 62;
    return 63;
}

void decode(bool mat[1010][1010], int h, int w) {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < (w + 5) / 6; j++) {
            int bit = getbit(code[i][j]);
            for (int k = 0; k < 6; k++) {
                mat[i][j*6+k] = ((bit >> (5 - k)) & 1) == 1;
            }
        }
    }
}

void init() {
    for (int i = 0; i < n; i++) scanf("%s", code[i]);
    decode(ma, n, m);
    for (int i = 0; i < p; i++) scanf("%s", code[i]);
    decode(pattern, p, p);
}

bool tm[1010][1010];
void rotate() {
    for (int i = 0; i < p; i++) {
        for (int j = 0; j < p; j++) {
            tm[i][j] = pattern[j][p-1-i];
        }
    }
    for (int i = 0; i < p; i++) for (int j = 0; j < p; j++)
                                    pattern[i][j] = tm[i][j];
}
void mirror() {
    for (int i = 0; i < p; i++) {
        for (int j = 0; j < p; j++) {
            tm[i][j] = pattern[i][p-1-j];
        }
    }
    for (int i = 0; i < p; i++) for (int j = 0; j < p; j++)
                                    pattern[i][j] = tm[i][j];
}

set<ull> seen;

void solve() {
    seen.clear();
    int ans = 0;
    compute_hash(pattern, p, p);
    ull hp = ha[0][0];
    seen.insert(hp);
    compute_hash(ma, n, m);
    for (int i = 0; i + p <= n; i++) {
        for (int j = 0; j + p<= m; j++) {
            if (ha[i][j] == hp) ans++;
            mh[i][j] = ha[i][j];
        }
    }
    for (int k = 0; k < 7; k++) {
        if (k == 3) mirror();
        else rotate();
        compute_hash(pattern, p, p);
        hp = ha[0][0];
        if (seen.find(hp) != seen.end()) continue;
        seen.insert(hp);
        for (int i = 0; i + p <= n; i++) {
            for (int j = 0; j + p <= m; j++) {
                if (mh[i][j] == hp) ans++;
            }
        }
    }
    printf("%d\n", ans);
}

int main() {
    for (;;) {
        scanf("%d%d%d", &m, &n, &p);
        if (n == 0 && m == 0 && p == 0) break;
        init();
        solve();
    }
    return 0;
}

Measured memory_bytes: 28008