def getkmpnext(S): N = len(S) KMPNext = [-1] * (N + 1) j = -1 for i in range(1, N + 1): while j >= 0 and S[i - 1] != S[j]: j = KMPNext[j] j += 1 if i == N or S[i] != S[j]: KMPNext[i] = j else: KMPNext[i] = KMPNext[j] return KMPNext def kmp(S, T): N = len(S) M = len(T) KMPNext = getkmpnext(T) j = 0 Res = 0 for i in range(N): while j != KMPNext[0] and S[i] != T[j]: j = KMPNext[j] j += 1 if j == M: Res += 1 j = KMPNext[j] return Res S = input() Q = int(input()) Ans = 0 for _ in range(Q): T = input() Ans += kmp(S, T) print(Ans)