#include <iostream>
#include <cstring>
 
using namespace std;
 
#define B 9973
 
int base64(char ch)
{
    if ('A' <= ch && ch <= 'Z')
        return ch - 'A';
    if ('a' <= ch && ch <= 'z')
        return ch - 'a' + 26;
    if ('0' <= ch && ch <= '9')
        return ch - '0' + 52;
    return ch == '+' ? 62 : 63;
}
 
int w, h, p, image_bit[1024][1024], pattern_bit[128][128], backup[128][128];
char image[1000][200], pattern[100][20];
typedef unsigned long long ull;
ull row_hash[1024][1024], hashes[8];    // ?算所有P*P子?的哈希?所用的??矩?与目?的8?????的哈希?
 
template<size_t raw_rows, size_t raw_cols, size_t bit_rows, size_t bit_cols>
inline void base64_to_bit(char (&raw)[raw_rows][raw_cols], int (&bit)[bit_rows][bit_cols], int h)
{
    memset(bit, 0, sizeof(bit));
    for (int i = 0; i < h; ++i)
        for (int j = 0; raw[i][j]; j++)
        {
            const int x = base64(raw[i][j]);
            for (int k = 0; k < 6; ++k)
                if (x & (1 << k))
                    bit[i][j * 6 + 5 - k] = 1;
        }
}
 
int main()
{
    while (~scanf("%d%d%d", &w, &h, &p), w)
    {
        for (int i = 0; i < h; ++i)
            scanf(" %s", image[i]);
        for (int i = 0; i < p; ++i)
            scanf(" %s", pattern[i]);
        base64_to_bit(image, image_bit, h);
        base64_to_bit(pattern, pattern_bit, p);
        for (int d = 0; d < 8; ++d) // ??理出小?8???的哈希?
        {
            memcpy(backup, pattern_bit, sizeof(pattern_bit));
            for (int i = 0; i < p; ++i)
                for (int j = 0; j < p; ++j)
                    pattern_bit[p - 1 - j][i] = backup[i][j];   // 旋?
            if (d == 4)
            {
                memcpy(backup, pattern_bit, sizeof(pattern_bit));
                for (int i = 0; i < p; ++i)
                    for (int j = 0; j < p; ++j)
                        pattern_bit[i][p - 1 - j] = backup[i][j]; // 翻?
            }
            hashes[d] = 0;
            for (int i = 0; i < p; ++i)
                for (int j = 0; j < p; ++j)
                    hashes[d] = hashes[d] * B + pattern_bit[i][j];
        }
        ull t1 = 1ULL;  // B的p次方
        for (int i = 0; i < p; ++i)
            t1 *= B;
        for (int i = 0; i < h; ++i) // 按行方向?算哈希?
        {
            ull e = 0;
            for (int j = 0; j < w; ++j)
            {
                e = e * B + image_bit[i][j];
                if (j >= p)
                    e -= t1 * image_bit[i][j - p];
                row_hash[i][j] = e;
            }
        }
        ull t2 = 1ULL;
        for (int i = 0; i < p; ++i)
            t2 *= t1;
        int ans = 0;
        for (int i = p - 1; i < w; i++) // 按列方向?算哈希?
        {
            ull e = 0;
            for (int j = 0; j < h; ++j)
            {
                e = e * t1 + row_hash[j][i];
                if (j >= p)
                    e -= t2 * row_hash[j - p][i];
                if (j >= p - 1) // pattern是正方形，坐?最小p-1
                    for (int d = 0; d < 8; ++d) // 8?模式
                        if (hashes[d] == e)
                        {
                            ans++;
                            break;
                        }
            }
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 15676