from collections import Counter S = input() M = int(input()) ls = len(S) counter = Counter() for i in range(ls): for j in range(1, 11): if i + j <= ls: counter[S[i:i + j]] += 1 ans = 0 for _ in range(M): ans += counter[input()] print(ans)