#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




template<typename T>
class vector_hash{
private:
    typedef long long int ll;
    typedef unsigned long long int ull;
    typedef unsigned long ul;
    typedef vector<ull> Hash;
    
    const ull mod;
    const ull roll;
    Hash H;
    vector<T> W;
    
    ull mod_pow(ull a,ull x){
        a%=mod;
        ll ans=1;
        while(x>0){
            if(x&1){ans*=a; ans%=mod;}
            a*=a; a%=mod;
            x>>=1;
        }
        return ans;
    }
    
    pll Ex_gcd(ll a,ll b){
        if(b==0){return {1,0};}
        pll ret=Ex_gcd(b,a%b);
        ret.F-=a/b*ret.S;
        return {ret.S,ret.F};
    }
    
    ull R(ull a){
        ll ret=Ex_gcd(a,mod).F;
        ret%=mod;
        if(ret<0){ret+=mod;}
        return ret;
    }
    
    void mk_hash(){
        H[0]=W[0]%mod;
        for(int i=1;i<H.size();i++){
            H[i]=H[i-1]*roll%mod+W[i]%mod;
            H[i]%=mod;
        }
    }
    
public:
    //乱数を使って初期化するべき?
    vector_hash(const vector<T> &W={},ull mod=1000000007,ull roll=65537):W(W),mod(mod),roll(roll),H(W.size()){
        mk_hash();
    }
    
    void push_back(const vector<T> &A){
        ull d=H.size();
        H.resize(d+A.size());
        W.resize(d+A.size());
        for(ull i=d;i<H.size();i++){
            W[i]=A[i-d];
            H[i]=W[i]%mod;
            if(i!=0){
                H[i]+=H[i-1]*roll%mod;
            }
            H[i]%=mod;
        }
    }
    
    void push_back(T c){
        W.push_back(c);
        H.push_back(c)%mod;
        if(H.size()==1){return;}
        H[H.size()-1]+=H[H.size()-2]*roll%mod;
        H[H.size()-1]%=mod;
    }
    
    unsigned long size() const {return W.size();}
    
    const ull & MOD() const {return mod;}
    
    const ull & ROLL() const {return roll;}
    
    T & operator [] (const ul &s){
        assert(s<H.size());
        return H[s];
    }
    
    bool operator == (vector_hash &S) const {
        return S.size()==H.size() && H[H.size()-1]==S[H.size()-1];
    }
    
    //共通の長さ、初めて違う文字のインデックス
    unsigned long same(vector_hash &W) const {
        ul r=min(H.size(),W.size())-1;
        if(H[r]==W[r]){return r+1;}
        ul l=0;
        while(r-l>3){
            ul m=l+(r-l)/2;
            if(W[m]!=H[m]){r=m;}
            else{l=m+1;}
        }
        for(ul i=l;i<r;i++){
            if(W[i]!=H[i]){return i;}
        }
        return r;
    }
    
    //[l,r)
    ull hash(ul l,ul r){
        assert(l<r && r<=H.size());
        if(l==0){return H[r-1];}
        return (mod+H[r-1]-H[l-1]*mod_pow(roll,r-l)%mod)%mod;
    }
    
    ull merge_hash(ull hash,ul Long){
        return (H[H.size()-1]*mod_pow(roll,Long)%mod+hash)%mod;
    }
};


class hash_2d{
private:
    typedef unsigned long ul;
    typedef unsigned long long int ull;
    typedef vector_hash<ull> VH;
    typedef pair<ul,ul> point;
    ull mod,roll,mod2,roll2;
    ul H,W;
    ul h,w;
    vector<vector<ull>> A;
    vector<VH> mid; //縦横逆
    vector<vector<ull>> hash;
    
    void mk_hash(){
        hash.resize(H+1-h,vector<ull>(W+1-w,0));
        vector<vector<ull>> midh(W+1-w,vector<ull>(H,0));
        for(int i=0;i<H;i++){
            VH v(A[i],mod,roll);
            for(int t=0;t+w<=W;t++){
                midh[t][i]=v.hash(t,t+w);
            }
        }
        for(int t=0;t+w<=W;t++){
            mid.push_back(VH(midh[t],mod2,roll2));
            for(int i=0;i+h<=H;i++){
                hash[i][t]=mid[t].hash(i,i+h);
            }
        }
    }
    
public:
    hash_2d(const vector<vector<ull>> &A,ul h,ul w,ull mod=1000000007,ull roll=837263374,ull mod2=1000006313,ull roll2=132847362):A(A),h(h),w(w),H(A.size()),W(A[0].size()),mod(mod),roll(roll),mod2(mod2),roll2(roll2){
        mk_hash();
    }
    
    vector<ull> & operator [] (const ul &s){
        return hash[s];
    }
    
    vector<point> find(ull a){
        vector<point> ret;
        for(int i=0;i<hash.size();i++){
            for(int t=0;t<hash[i].size();t++){
                if(hash[i][t]==a){ret.push_back({i,t});}
            }
        }
        return ret;
    }
    
    ul count(ull a){
        ul ret=0;
        for(int i=0;i<hash.size();i++){
            for(int t=0;t<hash[i].size();t++){
                if(hash[i][t]==a){ret++;}
            }
        }
        return ret;
    }
};

ull count(char c){
    if('A'<=c && c<='Z'){return c-'A';}
    if('a'<=c && c<='z'){return 26+c-'a';}
    if('0'<=c && c<='9'){return 52+c-'0';}
    if(c=='+'){return 62;}
    return 63;
}

vector<vector<ull>> to_vector(const vector<string> &F){
    vector<vector<ull>> ret(F.size(),vector<ull>(F.size()));
    for(int i=0;i<F.size();i++){
        for(int t=0;t*6<F.size();t++){
            ull a=count(F[i][t]);
            vector<ull> A(6);
            for(int h=0;h<6;h++){
                A[h]=a>>h&1;
            }
            reverse(A.begin(),A.end());
            for(int h=0;t*6+h<F.size() && h<6;h++){
                ret[i][t*6+h]=A[h];
            }
        }
    }
    return ret;
}
typedef pair<unsigned long,unsigned long> point;

int main(){
    ll w,h,p;
    while(cin>>w>>h>>p && w){
    vector<string> S(h);
    vector<vector<ull>> A(h,vector<ull>(w));
    for(int i=0;i<h;i++){
        cin>>S[i];
        for(int t=0;t<S[i].size();t++){
            ull a=count(S[i][t]);
            for(int h=0;h<6 && t*6+h<w;h++){
                A[i][t*6+h]=a>>(5-h)&1;
            }
        }
    }
    /*
    for(int i=0;i<h;i++){
        for(int t=0;t<A[i].size();t++){
            cout<<A[i][t];
        }
        cout<<endl;
    }
     */
    vector<string> F(p);
    for(int i=0;i<p;i++){
        cin>>F[i];
    }
    vector<vector<ull>> B=to_vector(F);
    set<point> Set;
    if(p<=h && w>=p){
        hash_2d H(A,p,p);
        for(int i=0;i<4;i++){
            vector<vector<ull>> Bd(p,vector<ull>(p));
            for(int i=0;i<p;i++){
                for(int t=0;t<p;t++){
                    Bd[i][t]=B[t][p-i-1];
                }
            }
            B=Bd;
            /*
            for(int i=0;i<B.size();i++){
                for(int t=0;t<B[i].size();t++){
                    cout<<B[i][t];
                }
                cout<<endl;
            }
             */
            for(int t=0;t<2;t++){
                if(t==1){
                    for(int h=0;h<p;h++){
                        reverse(Bd[h].begin(),Bd[h].end());
                    }
                }
                hash_2d b(Bd,p,p);
                vector<point> ret=H.find(b[0][0]);
                for(int i=0;i<ret.size();i++){
                    Set.insert(ret[i]);
                }
            }
        }
    }
    cout<<Set.size()<<endl;
    
    }
    return 0;
}





Measured memory_bytes: 118660