S, A = input(), 0 for i in [0] * int(input()): K, B = input(), 0 while -1 < i: i, A, B = S.find(K, i + B), A + B, 1 print(A)