from collections import defaultdict b=30 def str_to_num(s): res=[] for ss in s: res.append(ord(ss)-ord("A")+1) return res def calc_h(s): L=str_to_num(s) h=0 for i in range(len(L)): h+=L[i]*b**i return h S=input() d=defaultdict(int) for i in range(1,11): for j in range(len(S)-i+1): d[calc_h(S[j:j+i])]+=1 ans=0 M=int(input()) for _ in range(M): ans+=d[calc_h(input())] print(ans)