from collections import defaultdict S = input() S = [ord(i)-96 for i in S] l = len(S) b1 = 10**9+7 b2 = 10**5+7 mod = (1<<61)-1 p1, p2, h1, h2 = [1]*(l+1),[1]*(l+1),[0]*(l+1),[0]*(l+1) for i in range(l): p1[i+1] = (p1[i]*b1)%mod p2[i+1] = (p2[i]*b2)%mod h1[i+1] = (h1[i]*b1+S[i])%mod h2[i+1] = (h2[i]*b2+S[i])%mod def gethash(l,r): """2つの基数でのハッシュ値を返す""" a = (h1[r]-h1[l]*p1[r-l])%mod b = (h2[r]-h2[l]*p2[r-l])%mod return a, b d = defaultdict(int) for i in range(l): for j in range(1,11): if i+j<=l: a, b = gethash(i,i+j) d[str(a)+'_'+str(b)] += 1 M = int(input()) res = 0 for i in range(M): C = input() C = [ord(i)-96 for i in C] hash1, hash2 = 0,0 for num in C: hash1 = (hash1*b1+num)%mod hash2 = (hash2*b2+num)%mod res += d[str(hash1)+'_'+str(hash2)] print(res)