#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
#define INF 0x3f3f3f3f
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define M_PI 3.14159265358979323846
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define MAX_V 10101
#define maxn 1234
#define lowbit(X) (X & (-X))
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<PII,int>PPI;


int A[maxn][maxn];
int P[12][maxn][maxn];
char str[maxn];

void decode(char *str,int *num,int n){
	int t=strlen(str);
	int temp;
	for(int i=0;i<t;++i){
		if(str[i]<='Z' && str[i]>='A') temp=str[i]-'A';
		else if(str[i]<='z' && str[i]>='a') temp=str[i]-'a'+26;
		else if(str[i]<='9' && str[i]>='0')temp=str[i]-'0'+52;
		else if(str[i]=='+') temp=62;
		else temp=63;
		for(int j=0;j<6;++j){
			num[i*6+j]=(temp>>(5-j))&1;
		}
	}
}
/*
1234   51
5678   62
       73
       84
1 2
3 4

2 1
4 3       

*/
void right_rotate(int A[][maxn],int B[][maxn],int n){
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			B[j][n-1-i]=A[i][j];		
		}
	}
}
void turn_over(int A[][maxn],int B[][maxn],int n){
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			B[i][j]=A[i][n-1-j];
		}		
	}
}
void turn_over2(int A[][maxn],int B[][maxn],int n){
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			B[i][j]=A[n-1-i][j];
		}		
	}
}
bool same(int a,int b,int p){
	for(int i=0;i<p;++i){
		for(int j=0;j<p;++j){
			if(P[a][i][j]!=P[b][i][j]){
				return false;
			}
		}
	}
	return true;
}
//*************?????£?£°?*************
//???¨hash->build->gethash 
const int MAXN=1234;
ll psl[MAXN],psr[MAXN];
ll BL=1e9+17;
ll BR=1e9+3337;
ll ML=1e9+100658;
ll MR=1e9+10003;
ll hs[MAXN],hs2[MAXN];
void Hash(){
	psl[0]=1;
	psr[0]=1;
	for(int i=1;i<MAXN;++i){
		psl[i]=psl[i-1]*BL%ML;	
		psr[i]=psr[i-1]*BR%MR;
	}
}
void build(ll *hs,ll *s,int n){
	ll l=0,r=0;
	for(int i=0;i<=n;++i){
		l=(l*BL%ML+s[i])%ML;
		r=(r*BR%MR+s[i])%MR;
		if(l<0)l+=ML;
		if(r<0)r+=MR;
		hs[i+1]=(l<<32)|r;
	}
}
//×?±????? 
ll gethash(ll *hs,int b,int e){
	ll el=hs[e]>>32;
	ll er=hs[e]&0xffffffff;
	ll bl=hs[b]>>32;
	ll br=hs[b]&0xffffffff;
	ll l=el-bl*psl[e-b]%ML;
	ll r=er-br*psr[e-b]%MR;
	if(l<0)l+=ML;
	if(r<0)r+=MR;
	return (l<<32) | r;
}
ll HA[maxn][maxn];
ll HP[maxn][maxn];
//************?????£?£°?end*************
bool ok[12];
void presolve(int A[][maxn],ll HA[][maxn],int n,int m,int p){
	ll BS=1e9+17;
	ll BM=1e9+100009;
	ll BC=1;
	for(int i=0;i<p;++i) BC=(BC*BS)%BM;
	for(int j=0;j<m;++j){
		ll tt=0;
		for(int i=0;i<p;++i){
			tt=(tt*BS+A[i][j])%BM;
		}
		HA[0][j]=tt;
		if(HA[0][j]<0)HA[0][j]+=BM;
		for(int i=p;i<n;++i){
			HA[i-p+1][j]=(HA[i-p][j]*BS+A[i][j]-A[i-p][j]*BC)%BM;
			if(HA[i-p+1][j]<0) HA[i-p+1][j]+=BM;
		}
	}
}
int solve(int A[][maxn],int P[][maxn][maxn],int n,int m,int p){
	int ans=0;
	Hash();
	presolve(A,HA,n,m,p);
	for(int i=0;i<12;++i){
		if(ok[i]){
			presolve(P[i],HP,p,p,p);
			build(hs2,HP[0],p);
			for(int i=0;i+p-1<n;++i){
				build(hs,HA[i],m);
				ll temp=gethash(hs2,0,p);
				for(int j=0;j+p-1<m;++j){
					if(gethash(hs,j,j+p)==temp){
						ans++;
					}
				}
			}
		//	cout<<ans<<endl;			
		}
	}
	return ans;
}
int main()
{
	int n,m,p;
	while(scanf("%d%d%d",&m,&n,&p)){
		if(n==0 && m==0 && p==0)break;
		for(int i=0;i<n;++i){
			scanf("%s",str);
			decode(str,A[i],m);
		}
		for(int i=0;i<p;++i){
			scanf("%s",str);
			decode(str,P[0][i],p);
		}
		turn_over(P[0],P[4],p);
		turn_over2(P[0],P[8],p);
		for(int i=1;i<4;++i){
			right_rotate(P[i-1],P[i],p);	
			right_rotate(P[4+i-1],P[4+i],p);	
			right_rotate(P[8+i-1],P[8+i],p);
		}
		for(int i=0;i<12;++i)ok[i]=1;
		for(int i=0;i<12;++i){
			for(int j=i+1;j<12;++j){
				if(ok[i] && ok[j] && same(i,j,p)){
					ok[j]=0;
				}		
			}
		}
		printf("%d\n",solve(A,P,n,m,p));	
	}
	return 0;
}

Measured memory_bytes: 50352