#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

int base64(char c){
  if (c == '+') return 62;
  if (c == '/') return 63;
  if (isdigit(c)) return 52 + c - '0';
  if (islower(c)) return 26 + c - 'a';
  return c - 'A';
}

vector<vector<ll> > make_hash(vector<vector<int> > pat, int p, ll base1, ll base2){

  int n = pat.size();
  int m = pat[0].size();
  
  int R = max(0, n - p + 1);
  int C = max(0, m - p + 1);
  

  vector<vector<ll> > tmp(n, vector<ll>(C));
  vector<vector<ll> > res(R, vector<ll>(C));
  
  ll t = 1;
  REP(i, p) t = t * base1;
  
  REP(i, n){
    ll e = 0;
    REP(j, p) e = e * base1 + (pat[i][j] + 1);
    
    REP(j, C){
      tmp[i][j] = e;
      if (j + p < m){
        e = e * base1 - t * (pat[i][j] + 1) + pat[i][j + p] + 1;
      }
    }
  }

  t = 1;
  REP(i, p) t = t * base2;
  REP(j, C){
    ll e = 0;
    REP(i, p) e = e * base2 + tmp[i][j] + 1;
    REP(i, R){
      res[i][j] = e;
      if (i + p < n){
        e = e * base2 - t * (tmp[i][j] + 1) + tmp[i + p][j] + 1;
      }
    }
  }
  return res;
}

void rotate(vector<vector<int> > &pat){
  vector<vector<int> > r_pat(pat.back().size(), vector<int>(pat.size()));
  REP(i, pat.size()) REP(j, pat[i].size()){
    r_pat[i][j] = pat[j][pat.size() - i - 1];
  }
  pat = r_pat;
}

int main(){
  ios::sync_with_stdio(false);

  int w, h, p;
  while (cin >> w >> h >> p && w + h + p){
    vector<vector<int> > image(h, vector<int>(w));
    vector<vector<int> > pattern(p, vector<int>(p));
    
    REP(i, h){
      string line;
      cin >> line;
      REP(j, line.size()) REP(k, 6) if (j * 6 + k < w){
        image[i][j * 6 + k] = (base64(line[j]) >> (5 - k)) & 1;
      }
    }
    
    REP(i, p){
      string line;
      cin >> line;
      REP(j, line.size()) REP(k, 6) if (j * 6 + k < p){
        pattern[i][j * 6 + k] = (base64(line[j]) >> (5 - k)) & 1;
      }
    }

    vector<vector<vector<int> > > patterns;
    REP(i, 4){
      patterns.push_back(pattern);
      rotate(pattern);
    }
    
    REP(i, pattern.size()){
      reverse(ALL(pattern[i]));
    }
    
    REP(i, 4){
      patterns.push_back(pattern);
      rotate(pattern);
    }

    int res = 1e9;

    vector<ll> mods;
    mods.push_back(1000 * 1000 * 1000 + 9);
    mods.push_back(1000 * 1000 * 1000 + 7);
    mods.push_back(1000 * 1000 * 100 + 7);

    REP(i, mods.size()){
      ll mod1 = mods[i];
      ll mod2 = mods[(i + 1) % mods.size()];
      vector<vector<ll> > image_hash = make_hash(image, p, mod1, mod2);
      
      vector<vector<vector<ll> > > pattern_hashes;
      REP(i, patterns.size()){
        pattern_hashes.push_back(make_hash(patterns[i], p, mod1, mod2));
        assert(pattern_hashes.back().size() == 1);
      }

      int count = 0;
      REP(i, image_hash.size()) REP(j, image_hash[i].size()){
        bool found = false;
        REP(k, patterns.size()){
          if (image_hash[i][j] == pattern_hashes[k][0][0]) found = true;
        }
        if (found) count++;
      }
      res = min(res, count);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 22856