S = input() cnt = {} n = len(S) for i in range(n): tot = 0 for j in range(10): if i + j == n: break tot *= 30 tot += ord(S[i + j]) - 64 cnt[tot] = cnt.get(tot, 0) + 1 ans = 0 m = int(input()) for _ in range(m): S = input() tot = 0 for s in S: tot *= 30 tot += ord(s) - 64 ans += cnt.get(tot, 0) print(ans)