from collections import defaultdict class RollingHash: def __init__(self,N,mod=(1<<61)-1,base=37): self.N = N self.mod = mod self.base = base self.pw = [1]*(self.N+1) tmp = 1 for i in range(self.N+1): self.pw[i] = tmp tmp = tmp*self.base%self.mod self.hs = [0]*(self.N+1) def build_from_int(self,S): tmp = 0 for i in range(self.N): tmp = (tmp*self.base+S[i]+1)%self.mod self.hs[i+1] = tmp def build_from_str(self,S): tmp = 0 for i in range(self.N): tmp = (tmp*self.base+ord(S[i]))%self.mod self.hs[i+1] = tmp def get_hash(self,l,r): return (self.hs[r]-self.hs[l]*self.pw[r-l])%self.mod def make_hash(self,S): tmp = 0 for i in range(len(S)): tmp = (tmp*self.base+ord(S[i]))&self.mod return tmp S = input() N = len(S) M = int(input()) rh = RollingHash(N) rh.build_from_str(S) d = defaultdict(lambda:0) for i in range(1,min(N,10)+1): for j in range(N-i+1): d[rh.get_hash(j,j+i)] += 1 ans = 0 for i in range(M): C = input() ans += d[rh.make_hash(C)] print(d[rh.make_hash(C)]) print(ans)