from collections import Counter s = input() d = Counter() for i in range(1,11): for j in range(len(s)-i+1): d[s[j:j+i]] += 1 m = int(input()) print(sum(d[input()] for _ in range(m)))