#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
int base64_to_int(char c) {
  if('A' <= c && c <= 'Z') {
    return c - 'A';
  } else if('a' <= c && c <= 'z') {
    return c - 'a' + 26;
  } else if('0' <= c && c <= '9') {
    return c - '0' + 52;
  } else if(c == '+') {
    return 62;
  } else {
    return 63;
  }
}
int calc(int h, int w, int p, const vector<vector<bool>> &a, const vector<bitset<100>> &pattern) {
  vector<vector<bitset<100>>> c(h, vector<bitset<100>>(w));
  for(int i=0;i<(h);++i) {
    bitset<100> bs;
    for(int j=0;j<(p);++j) {
      bs <<= 1;
      bs[p] = 0;
      bs[0] = a[i][j];
    }
    c[i][0] = bs;
    for(int j=(p);j<(w);++j) {
      bs <<= 1;
      bs[p] = 0;
      bs[0] = a[i][j];
      c[i][j-p+1] = bs;
    }
  }
  ll cnt = 0;
  for(int i=0;i<(h-p+1);++i) {
    for(int j=0;j<(w-p+1);++j) {
      bool ok = true;
      for(int k=0;k<(p);++k) {
        ok &= c[i+k][j] == pattern[k];
      }
      cnt += ok;
    }
  }
  return cnt;
}
bool solve() {
  int w, h, p; cin >> w >> h >> p;
  if(w == 0) return false;
  vector<vector<bool>> a(h, vector<bool>(w));
  for(int i=0;i<(h);++i) {
    string s; cin >> s;
    for(int j=0;j<((int)(s.size()));++j) {
      ll tmp = base64_to_int(s[j]);
      for(int k=0;k<(6);++k) {
        if(j * 6 + k < w) a[i][j*6+k] = (tmp>>(5-k))&1;
      }
    }
  }
  vector<vector<bool>> b(p, vector<bool>(p));
  for(int i=0;i<(p);++i) {
    string s; cin >> s;
    for(int j=0;j<((int)(s.size()));++j) {
      ll tmp = base64_to_int(s[j]);
      for(int k=0;k<(6);++k) {
        if(j*6+k < w) b[i][j*6+k] = (tmp>>(5-k))&1;
      }
    }
  }
  vector<vector<bitset<100>>> patterns(8, vector<bitset<100>>(p));
  for(int i=0;i<(p);++i) {
    bitset<100> bs;
    for(int j=0;j<(p);++j) {
      bs <<= 1;
      bs[p] = 0;
      bs[0] = b[i][j];
    }
    patterns[0][i] = bs;
  }
  for(int i=0;i<(p);++i) {
    for(int j=0;j<(p);++j) {
      patterns[1][i][j] = patterns[0][j][p-1-i];
      patterns[2][i][j] = patterns[0][p-1-i][p-1-j];
      patterns[3][i][j] = patterns[0][p-1-j][i];
      patterns[4][i][j] = patterns[0][i][p-1-j];
      patterns[5][i][j] = patterns[0][j][i];
      patterns[6][i][j] = patterns[0][p-1-i][j];
      patterns[7][i][j] = patterns[0][p-1-j][p-1-i];
    }
  }
  vector<bool> sel(8);
  for(int i=0;i<(8);++i) {
    if(sel[i]) continue;
    for(int j=(i+1);j<(8);++j) {
      if(sel[j]) continue;
      bool same = true;
      for(int k=0;k<(p);++k) {
        for(int l=0;l<(p);++l) {
          same &= patterns[i][k][l] == patterns[j][k][l];
        }
      }
      sel[j] = same;
    }
  }
  int ans = 0;
  for(int i=0;i<(8);++i) {
    if(sel[i]) continue;
    ans += calc(h, w, p, a, patterns[i]);
  }
  cout << ans << endl;
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(solve()) {}
}



Measured memory_bytes: 18840