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

typedef long long ll;
typedef unsigned long long ull;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define B 1000000007
#define B2 10007

int W,H,P;
string s;
bool a[1100][1100];
bool b[1100][1100];
ull hs[1000][1000];
map<ull,int> cnt;
set<ull> used;

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

int main(){
  while(1){
    cin>>W>>H>>P;
    if(W==0)break;
    cnt.clear();
    used.clear();
    rep(i,H){
      cin>>s;
      rep(j,s.size()){
        rep(k,6){
          a[i][j*6+5-k]=(f(s[j])>>k)&1;
        }
      }
    }
    rep(i,P){
      cin>>s;
      rep(j,s.size()){
        rep(k,6){
          b[i][j*6+5-k]=(f(s[j])>>k)&1;
        }
      }
    }
    if(H<P||W<P){
      cout<<0<<endl;
      continue;
    }

    rep(i,H){
      ull h=0,elim=1;
      rep(j,P){
        h*=B;
        h+=a[i][j];
        elim*=B;
      }
      hs[i][0]=h;
      repl(j,P,W){
        h*=B;
        h-=elim*a[i][j-P];
        h+=a[i][j];
        hs[i][j-P+1]=h;
      }
    }
    rep(j,W-P+1){
      ull h=0,elim=1;
      rep(i,P){
        h*=B2;
        h+=hs[i][j];
        elim*=B2;
      }
      cnt[h]++;
      repl(i,P,H){
        h*=B2;
        h-=elim*hs[i-P][j];
        h+=hs[i][j];
        cnt[h]++;
      }
    }
    
    int res=0;
    rep(x,2)rep(y,2)rep(z,2){
      ull h=0;
      for(int i=(x?0:P-1);(x?i<P:i>=0);i+=(x?+1:-1)){
        ull h2=0;
        h*=B2;
        for(int j=(y?0:P-1);(y?j<P:j>=0);j+=(y?+1:-1)){
          h2*=B;
          h2+=(z?b[i][j]:b[j][i]);
        }
        h+=h2;
      }
      if(used.find(h)!=used.end())continue;
      used.insert(h);
      res+=cnt[h];
    }
    cout<<res<<endl;
  }
  return 0;
}

