#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
using ll = long long;

class rolling_hash_2d {
    using ll = long long;
public:
    rolling_hash_2d(std::vector<std::vector<int>> const& v)
        : H(v.size()), W(v[0].size()),
          p(2, std::vector<std::vector<ll>>(2, std::vector<ll>(std::max(H, W) + 1, 1))),
          hs(2, std::vector<std::vector<ll>>(H + 1, std::vector<ll>(W + 1)))
    {
        for(int i = 0; i < 2; ++i) {
            for(int j = 0; j < 2; ++j) {
                for(int k = 0; k + 1 < max(W, H); ++k) {
                    p[i][j][k + 1] = p[i][j][k] * B[i] % M[j];
                }
            }
        }
        for(int i = 0; i < 2; ++i) {
            for(int j = 0; j < H; ++j) {
                for(int k = 0; k < W; ++k) {
                    assert(j + 1 < hs[i].size());
                    hs[i][j + 1][k + 1] = (hs[i][j + 1][k] * B[i] + v[j][k]) % M[i];
                }
            }
        }
        for(int i = 0; i < 2; ++i) {
            for(int j = 0; j < H; ++j) {
                for(int k = 0; k < W; ++k) {
                    assert(j + 1 < hs[i].size());
                    hs[i][j + 1][k + 1] = ((hs[i][j][k + 1] * B[!i]) + hs[i][j + 1][k + 1]) % M[i];
                }
            }
        }
    }

    // [y1, y2) x [x1, x2)
    std::pair<ll, ll> query(int y1, int x1, int y2, int x2) const { // too slow
        std::pair<ll, ll> res(0, 0);
        for(int i = 0; i < 1; ++i) { // workaround
            auto& r = (i == 0 ? res.first : res.second);
            r = (hs[i][y2][x2] - hs[i][y2][x1] * p[i][i][x2 - x1] % M[i] + M[i]) % M[i];
            r = (r - hs[i][y1][x2] * p[!i][i][y2 - y1] % M[i] + M[i]) % M[i];
            r = (r + (hs[i][y1][x1] * p[!i][i][y2 - y1] % M[i]) * p[i][i][x2 - x1] % M[i]) % M[i];
        }
        return res;
    }

private:
    static constexpr ll B[2] = {9973, 100000007};
    static constexpr ll M[2] = {1000000007, 1000000009};
    int const H, W;
    std::vector<std::vector<std::vector<ll>>> p;
    std::vector<std::vector<std::vector<ll>>> hs;
};

constexpr ll rolling_hash_2d::B[2];
constexpr ll rolling_hash_2d::M[2];


vector<int> convert6(char c) {
    int d = 0;
    if('A' <= c && c <= 'Z') {
        d = c - 'A';
    } else if('a' <= c && c <= 'z') {
        d = c - 'a' + 26;
    } else if('0' <= c && c <= '9') {
        d = c - '0' + 52;
    } else if(c == '+') {
        d = 62;
    } else {
        d = 63;
    }
    vector<int> res(6);
    for(int i = 0; i < 6; ++i) {
        res[i] = 1 & (d >> 5 - i);
    }
    return res;
}

vector<int> convert(string const& s) {
    vector<int> res;
    for(auto c : s) {
        auto b6 = convert6(c);
        for(auto x : b6) {
            res.push_back(x);
        }
    }
    return res;
}

vector<vector<int>> rot(vector<vector<int>> const& v) {
    int const n = v.size();
    vector<vector<int>> res(n, vector<int>(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            res[i][j] = v[n - 1 - j][i];
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int w, h, p;
    while(cin >> w >> h >> p, w) {
        vector<vector<int>> image(h);
        vector<vector<int>> pattern(p);
        for(int i = 0; i < h; ++i) {
            string s; cin >> s;
            image[i] = convert(s);
            image[i].resize(w);
        }
        for(int i = 0; i < p; ++i) {
            string s; cin >> s;
            pattern[i] = convert(s);
            pattern[i].resize(p);
        }

        rolling_hash_2d image_hs(image);
        vector<vector<int>> match(h, vector<int>(w));
        for(int m = 0; m < 2; ++m) {
            for(int r = 0; r < 4; ++r) {
                rolling_hash_2d pattern_hs(pattern);
                for(int i = 0; i + p <= h; ++i) {
                    for(int j = 0; j + p <= w; ++j) {
                        auto hs1 = image_hs.query(i, j, i + p, j + p);
                        auto hs2 = pattern_hs.query(0, 0, p, p);
                        match[i][j] |= hs1 == hs2;
                    }
                }
                pattern = rot(pattern);
            }
            for(int i = 0; i < p; ++i) {
                reverse(begin(pattern[i]), end(pattern[i]));
            }
        }

        int res = 0;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                res += match[i][j];
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 30604