import java.util.*; class Main { public static List findSubstring(String s, String[] words) { List result = new ArrayList<>(); if (s == null || s.length() == 0 || words == null || words.length == 0) return result; int wordLen = words[0].length(); int totalLen = wordLen * words.length; if (s.length() < totalLen) return result; Map wordCount = new HashMap<>(); for (String w : words) wordCount.put(w, wordCount.getOrDefault(w, 0) + 1); for (int i = 0; i <= s.length() - totalLen; i++) { Map seen = new HashMap<>(); int j = 0; while (j < words.length) { int start = i + j * wordLen; String sub = s.substring(start, start + wordLen); if (!wordCount.containsKey(sub)) break; seen.put(sub, seen.getOrDefault(sub, 0) + 1); if (seen.get(sub) > wordCount.get(sub)) break; j++; } if (j == words.length) result.add(i); } return result; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); int n = Integer.parseInt(sc.nextLine()); String[] words = new String[n]; for (int i = 0; i < n; i++) { words[i] = sc.nextLine(); } List indices = findSubstring(s, words); System.out.println("Starting indices of concatenated substrings: " + indices); } }