import java.io.*;
import java.util.*;

public class solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int P = scanner.nextInt();
        String note = scanner.next();
        
        for (int p = 0; p < P; p++) {
            String pat = scanner.next();
            boolean found = false;
            
            for (int i = 0; i + pat.length() <= note.length(); i++) {
                char[] mapping = new char[128];
                char[] inverse = new char[128];
                
                Boolean match = true;
                
                for (int j = 0; j < pat.length(); j++) {
                    char in_pat = pat.charAt(j);
                    char in_note = note.charAt(i + j);

                    if (mapping[in_pat] == in_note) continue;

                    if (mapping[in_pat] != 0 || inverse[in_note] != 0) {
                        match = false;
                        break;
                    }

                    mapping[in_pat] = in_note;
                    inverse[in_note] = in_pat;
                }

                if (match) {
                    found = true;
                    System.out.println(i);
                    break;
                }
            }

            if (!found) {
                System.out.println("-");
            }
        }
    }
}
