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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

struct RollingHash{
  const LL BX, BY, M1, M2;
  int H, W;
  vector<LL> pow1, pow2;
  VVL hash1, hash2;
  RollingHash(const VVI& str): BX(1009), BY(1013), M1(1000000007), M2(1000000009){
	H = SZ(str), W = SZ(str[0]);
	hash1 = VVL(H+1, VL(W+1));
	hash2 = VVL(H+1, VL(W+1));
	pow1.assign(W+1,1);
	pow2.assign(H+1,1);
	REP(i,W) pow1[i+1] = pow1[i] * BX % M1;
	REP(i,H) pow2[i+1] = pow2[i] * BY % M1;

	REP(y,H){
	  LL row = 0;
	  REP(x,W){
		row = (row + str[y][x]) * BX % M1;
		hash1[y+1][x+1] = (hash1[y][x+1] * BY % M1 + row) % M1;
	  }
	}
  }

  // [l,r), 0 <= l < r <= n
  pair<LL,LL> hash(int x1, int y1, int x2, int y2){
	pair<LL,LL> res(0,0);
	res.first = (hash1[y2][x2] - hash1[y1][x2] * pow2[y2-y1] % M1 + M1) % MOD;
	res.first = (res.first - hash1[y2][x1] * pow1[x2-x1] % M1 + M1) % MOD;
	res.first = (res.first + hash1[y1][x1] * pow1[x2-x1] % M1 * pow2[y2-y1] % M1 + M1) % MOD;
	//res.second = ((hash2[r] - hash2[l] * pow2[r-l]) % M2 + M2) % M2;
	return res;
  }
};

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W, P;
  while(cin>>W>>H>>P,H){
	VVI xs(H, VI(W));
	VVI pat(P, VI(P));
	REP(y,H){
	  for(int i=0;i<W;i+=6){
		char c;
		cin >> c;
		c = decode(c);
		for(int j=0;j<6&&i+j<W;++j){
		  xs[y][i+j] = (c>>(5-j)&1);
		}
	  }
	}
	REP(y,P){
	  for(int i=0;i<P;i+=6){
		char c;
		cin >> c;
		c = decode(c);
		for(int j=0;j<6&&i+j<P;++j){
		  pat[y][i+j] = (c>>(5-j)&1);
		}
	  }
	}
	/*
	REP(y,H){
	  REP(x,W)cout<<xs[y][x];
	  cout<<endl;
	}
	  cout<<endl;
	REP(y,P){
	  REP(x,P)cout<<pat[y][x];
	  cout<<endl;
	}
	cout<<endl;
	*/
	vector<PLL> pats;
	REP(i,4){
	  RollingHash pt(pat);
	  pats.EB(pt.hash(0,0,P,P));

	  VVI tmp = pat;
	  REP(y,P) REP(x,P)
		pat[P-1-x][y] = tmp[y][x];
	}
	REP(y,P) REP(x,P/2)
	  swap(pat[y][x], pat[y][P-1-x]);
	REP(i,4){
	  RollingHash pt(pat);
	  pats.EB(pt.hash(0,0,P,P));

	  VVI tmp = pat;
	  REP(y,P) REP(x,P)
		pat[P-1-x][y] = tmp[y][x];
	}

	RollingHash in(xs);
	int ans = 0;
	for(int y=0;y+P<=H;++y)
	  for(int x=0;x+P<=W;++x){
		auto h = in.hash(x,y,x+P,y+P);
		if(find(ALL(pats), h) != end(pats))
		  ++ans;
	  }
	cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 22624