import sys readline=sys.stdin.readline from collections import defaultdict S=readline().rstrip() N=len(S) cnt=defaultdict(int) for le in range(1,11): for i in range(N-le+1): cnt[S[i:i+le]]+=1 M=int(readline()) ans=0 for m in range(M): C=readline().rstrip() ans+=cnt[C] print(ans)