#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{
  int H, W;
  const LL BX1, BY1, BX2, BY2, M1, M2;
  vector<LL> powX1, powX2, powY1, powY2;
  VVL hash1, hash2;
  RollingHash(const vector<vector<int>>& str): BX1(1007), BY1(1009), BX2(1011), BY2(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));
	powX1.assign(W+1,1);
	powX2.assign(W+1,1);
	powY1.assign(H+1,1);
	powY2.assign(H+1,1);
	REP(i,W){
	  powX1[i+1] = powX1[i] * BX1 % M1;
	  powX2[i+1] = powX2[i] * BX2 % M2;
	}
	REP(i,H){
	  powY1[i+1] = powY1[i] * BY1 % M1;
	  powY2[i+1] = powY2[i] * BY2 % M2;
	}

	REP(y,H){
	  LL row1 = 0;
	  LL row2 = 0;
	  REP(x,W){
		row1 = (row1 * BX1 + str[y][x]) % M1;
		row2 = (row2 * BX2 + str[y][x]) % M2;
		hash1[y+1][x+1] = (hash1[y][x+1] * BY1 % M1 + row1) % M1;
		hash2[y+1][x+1] = (hash2[y][x+1] * BY2 % M2 + row2) % M2;
	  }
	}
  }

  // [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]
				 + M1 - hash1[y1][x2] * powY1[y2-y1] % M1
				 + M1 - hash1[y2][x1] * powX1[x2-x1] % M1
				 + hash1[y1][x1] * powX1[x2-x1] % M1 * powY1[y2-y1] % M1) % M1;
	res.second = (hash2[y2][x2]
				  + M2 - hash2[y1][x2] * powY2[y2-y1] % M2
				  + M2 - hash2[y2][x1] * powX2[x2-x1] % M2
				  + hash2[y1][x1] * powX2[x2-x1] % M2 * powY2[y2-y1] % 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);
		}
	  }
	}

	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: 22680