#include<bits/stdc++.h>
using namespace std;
typedef bitset<100> bt;

bt dc[256];
bt fie[1001][1001];
bool inp[1001][1001];
struct worry{
  bt d[111];
  int p;
  void set(const vector<string> &s,int p){
    this->p = p;
    bool xp[101][101]={};
    for(int i=0;i<p;i++){
      int cnt = 0;
      for(int j=0;j<(p+5)/6;j++){
        bt a = 1;
        for(int k=5;k>=0&&cnt<p;k--,cnt++) {
          if( (dc[(int)s[i][j]] & (a<<k)).any() )
            xp[cnt][i] = 1;  
          else
            xp[cnt][i] = 0;
        }
      }
    }

    for(int i=0;i<p;i++){
      d[i] = 0;
      for(int j=0;j<p;j++){
        d[i] <<= 1;
        d[i] |= xp[j][i];
      }
    }
  }
  bool operator==(const worry& a) const{
    for(int i=0;i<p;i++)
      if( a.d[i] != d[i] ) return false;
    return false;
  }

  void rotate(){
    bt w[111];
    for(int i=0;i<p;i++){
      w[i] = 0;
      for(int j=0;j<p;j++){
        bt r = 1;
        if( (d[p-j-1]&(r<<i)).any() )
          w[i] |= (r<<j);
      }
    }
    for(int i=0;i<p;i++) d[i] = w[i];
  }

  void rev(){
    bt w[111];
    for(int i=0;i<p;i++){
      w[i] = 0;
      for(int j=0;j<p;j++){
        bt r = 1;
        w[i] |= (((d[i]&(r<<(p-j-1))).any()?r:0))<<j;
      }
    }
    for(int i=0;i<p;i++)
       d[i] = w[i];      
  }

  void rav(){
    bt w[111];
    for(int i=0;i<p;i++){
      w[i] = d[p-i-1];
    }
    for(int i=0;i<p;i++)
       d[i] = w[i];      
  }

  void view(){
    cout << "worry view" << endl;
    for(int i=0;i<p;i++)
      cout << d[i] << endl;
  }

};

bool eq( const worry& a, const worry& b) {
  for(int i=0;i<a.p;i++){
      if( a.d[i] != b.d[i] ) return false;
  }
  return true;
}

void init(){
  int cnt = 0;
  for(char i='A';i<='Z';i++) dc[(int)i] = cnt++;
  for(char i='a';i<='z';i++) dc[(int)i] = cnt++;
  for(char i='0';i<='9';i++) dc[(int)i] = cnt++;
  dc['+'] = cnt++;
  dc['/'] = cnt++;
}

int W,H,P;
worry wr[12];
int T;

bool check(int x,int y,const worry &w){
  //   cout << x << " , " << y << endl;
  for(int i=0;i<P;i++){
    /*if( T==2 && i== 0 && !(fie[x][y+i].test(99)) ){ cout << "comp: " << endl;
      cout << w.d[i] << endl<< fie[x][y+i] << endl;
      }*/
    if( w.d[i] != fie[x][y+i] ) return false;
  }
  return true;
}

void view(){
  cout <<"view" << endl;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++)
      cout << inp[j][i];
    cout << endl;
  }
}

int main(){
  init();
  //cout << dc['8'] << endl;
  int ttt=0;
  while( cin >> W >> H >> P && ( W || H || P ) ){
    memset(inp,0,sizeof(inp));
    for(int i=0;i<H;i++){
      int cnt = 0;
      for(int j=0;j<(W+5)/6;j++){
        char c;
        cin >> c;
        bt a = 1;
        for(int k=5;k>=0&&cnt<W;k--,cnt++) {
          if( (dc[(int)c] & (a<<k)).any() )
            inp[cnt][i] = 1; 
          else
            inp[cnt][i] = 0;
        }
      }
    }
    for(int i=0;i<H;i++){
      fie[0][i] = 0;
      for(int j=0;j<P;j++){
        fie[0][i] <<= 1;
        fie[0][i] |= inp[j][i];
      }
      ///     cout << 0 << " , " << i << " "<< fie[0][i] << endl;
      for(int j=1;j<=W-P;j++){
        bt r = 1;
        fie[j][i] = fie[j-1][i] << 1;
        fie[j][i] |= inp[j+P-1][i];
        fie[j][i] &= (~(r<<P));
        //    cout << bt(~(1<<P)) << endl;
        //      cout << j << " , " << i << " "<< fie[j][i] << endl;
      }
    }

    vector<string> str;
    for(int i=0;i<P;i++){
      string in; cin >> in;
      str.push_back(in);
    }
    wr[0].set( str, P );
    for(int i=1;i<4;i++){
      wr[i] = wr[i-1];
      wr[i].rotate();
    }
    for(int i=0;i<4;i++){
      wr[i+4] = wr[i];
      wr[i+4].rev();
      wr[i+8] = wr[i];
      wr[i+8].rav();
    }
    vector<worry> v;
    for(int i=0;i<12;i++){
      bool f = true;
      for(int j=i+1;j<12;j++){
        if( eq(wr[i], wr[j]) ){
          f = false;
        }
      }
      if( f ) v.push_back(wr[i]);
    }

    /*T++;
    if( T == 2 ){
      for(int i=0;i<(int)v.size();i++)
        v[i].view();
      //view();
    }
    */
    int cnt = 0;
    for(int i=0;i<=H-P;i++)
      for(int j=0;j<=W-P;j++)
        for(int k=0;k<(int)v.size();k++)
          if( check(j,i,v[k]) ) cnt++;
    
    cout << cnt << endl;
   
  }

}

Measured memory_bytes: 17936