import sys input=lambda: sys.stdin.readline().rstrip() S=input() n=len(S) m=int(input()) import collections RH=collections.defaultdict(int) base=37;mod=10**9+7 for l in range(10): v=0 for i in range(l+1): v=((v+ord(S[i]))*base)%mod RH[v]+=1 for i in range(l+1,n): v=(((v-ord(S[i-l-1])*pow(base,l+1,mod))+ord(S[i]))*base)%mod RH[v]+=1 ans=0 for _ in range(m): C=input() lc=len(C) if lc>n: continue else: v=0 for i in range(lc): v=((v+ord(C[i]))*base)%mod ans+=RH[v] print(ans)