d=input() c=0 for i in range(int(input())): c+=d.count(input()) print(c)