from collections import Counter, defaultdict from random import randint S = input() hash_dict = defaultdict(lambda: randint(1, (1 << 64) - 1)) d = Counter() for i in range(len(S)): for j in range(1, 11): if i + j > len(S): continue # print(i, j, S[i : i + j + 1]) d[hash_dict[S[i : i + j]]] += 1 # print(d, hash_dict) M = int(input()) ans = 0 for _ in range(M): C = input() ans += d[hash_dict[C]] print(ans)