Base = 1676943010 MOD = 2147483647 S = input() Q = int(input()) Count = [dict() for _ in range(11)] for i in range(1, min(10, len(S)) + 1): SHash = 0 B = 1 for j in range(i - 1, -1, -1): SHash += ord(S[j]) * B SHash %= MOD B *= Base B %= MOD Count[i][SHash] = 1 for j in range(len(S) - i): SHash = ((SHash * Base - ord(S[j]) * B) + ord(S[i + j])) % MOD if SHash in Count[i]: Count[i][SHash] += 1 else: Count[i][SHash] = 1 Ans = 0 for _ in range(Q): T = input() if len(S) < len(T): continue THash = 0 B = 1 for i in range(len(T) - 1, -1, -1): THash += ord(T[i]) * B THash %= MOD B *= Base B %= MOD if THash in Count[len(T)]: Ans += Count[len(T)][THash] print(Ans)