import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) #https://github.com/shakayami/ACL-for-python/blob/master/lazysegtree.py class lazy_segtree(): def update(self,k):self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def all_apply(self,k,f): self.d[k]=self.mapping(f,self.d[k]) if (k>i) self.d[p]=x for i in range(1,self.log+1):self.update(p>>i) def get(self,p): assert 0<=p and p>i) return self.d[p] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n if l==r:return self.e l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<>i) if (((r>>i)<>i) sml,smr=self.e,self.e while(l>=1 r>>=1 return self.op(sml,smr) def all_prod(self):return self.d[1] def apply_point(self,p,f): assert 0<=p and p>i) self.d[p]=self.mapping(f,self.d[p]) for i in range(1,self.log+1):self.update(p>>i) def apply(self,l,r,f): assert 0<=l and l<=r and r<=self.n if l==r:return l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<>i) if (((r>>i)<>i) l2,r2=l,r while(l>=1 r>>=1 l,r=l2,r2 for i in range(1,self.log+1): if (((l>>i)<>i) if (((r>>i)<>i) def max_right(self,l,g): assert 0<=l and l<=self.n assert g(self.e) if l==self.n:return self.n l+=self.size for i in range(self.log,0,-1):self.push(l>>i) sm=self.e while(1): while(l%2==0):l>>=1 if not(g(self.op(sm,self.d[l]))): while(l>i) sm=self.e while(1): r-=1 while(r>1 and (r%2)):r>>=1 if not(g(self.op(self.d[r],sm))): while(r>=1 r>>=1 def get(self,i): res=0 i+=self.num while i: res=self.segfunc(res,self.lazy[i]) i>>=1 return res #sys.set_int_max_str_digits(0) input = sys.stdin.readline #n = int(input()) # mod = 2**61-1 #alist = [] #s = input() n,l,q = map(int,input().split()) lst = [cheapSegTree(l) for fjdfb in range(n)] base = random.randint(100,10000) s = [] base_pow = [pow(base,i,mod) for i in range(5000+10)] for i in range(n): t = list(input().rstrip()) s.append(t) temp = 0 for j in range(l): temp += (ord(t[j]) - ord('a')) * base_pow[j] temp %= mod lst[i].update(j,j+1,temp) for _ in range(q): query = list(input().split()) if query[0] == '1': t,k,c,d = query k = int(k) k -= 1 for i in range(n): if s[i][k] == c: lst[i].update(k,l,-((ord(c) - ord('a')) * base_pow[k])) lst[i].update(k,l,(ord(d) - ord('a')) * base_pow[k]) s[i][k] = d else: e,t = query t = t.rstrip() t = list(t) ans = 0 temp = 0 for i in range(len(t)): temp += (ord(t[i]) - ord('a')) * base_pow[i] temp %= mod for i in range(n): if lst[i].get(len(t)-1) == temp: ans += 1 print(ans)