from collections import defaultdict import math import sys import os from typing import * sys.setrecursionlimit(100000) is_local = "TERM_PROGRAM" in os.environ input = sys.stdin.readline INF = float('inf') def debug(*args, **kwargs): if is_local: print(*args, **kwargs) def I(): return input().rstrip() def IS(): return input().split() def II(): return int(input()) def IIS(): return map(int, input().split()) def LIIS(): return list(map(int, input().split())) MOD = 2**61 - 1 def main(): s = I() n = len(s) hashes = [[] for _ in range(10)] hashes[0].append(ord(s[0]) - ord("A")) pows = [1] for _ in range(10): pows.append((pows[-1]*26) % MOD) for i in range(10): if i >= n: break if i > 0: hashes[i].append((hashes[i-1][0]*26 + ord(s[i]) - ord("A")) % MOD) for j in range(n - i - 1): x = hashes[i][-1] x -= (ord(s[j]) - ord("A")) * pows[i] x %= MOD x = (x * 26) % MOD x += (ord(s[j+i+1]) - ord("A")) x %= MOD hashes[i].append(x) m = II() out = 0 for _ in range(m): ss = I() l = len(ss) h = 0 for i in range(l): h *= 26 h %= MOD h += ord(ss[i]) - ord("A") h %= MOD out += hashes[l-1].count(h) print(out) if __name__ == "__main__": main()