#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import Counter # %% S = readline().rstrip().decode() M = int(readline()) query = read().decode().split() # %% counter = [None] * 11 for L in range(11): counter[L] = Counter(S[i: i + L] for i in range(0, len(S) - L + 1)) # %% answer = sum(counter[len(C)][C] for C in query) print(answer)