import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.BitSet;
import java.util.StringTokenizer;

public class diamonds_nn_1 {
    static String VOWELS = "aeiou";
    static int[] LETTER_ID = new int[26];

    static {
        int cur = 0;
        for (int i = 0; i < 26; i++) {
            if (VOWELS.indexOf((char) (i + 'a')) >= 0) {
                LETTER_ID[i] = -1;
                continue;
            }
            LETTER_ID[i] = cur++;
        }
    }

    static int code(char c) {
        return LETTER_ID[c - 'a'];
    }

    static void solve() throws IOException {
        next();
        String str = next();
        int n = nextInt();
        int[] qs = new int[n];
        int maxLetter = 0;
        for (int i = 0; i < n; i++) {
            next();
            String f = next();
            int mask = 0;
            for (char c : f.toCharArray()) {
                mask |= 1 << code(c);
                maxLetter = Math.max(maxLetter, code(c));
            }
            qs[i] = mask;
        }
        int[] s = new int[str.length()];
        for (int i = 0; i < s.length; i++) {
            s[i] = code(str.charAt(i));
            maxLetter = Math.max(maxLetter, s[i]);
        }
        ++maxLetter;
        System.err.println(maxLetter);
        int[] ansL = new int[1 << maxLetter];
        Arrays.fill(ansL, -1);
        int[] ansR = new int[1 << maxLetter];
        int[] mc = new int[s.length + 1];
        int[] count = new int[maxLetter];
        for (int len = s.length; len >= 1; len--) {
            Arrays.fill(count, 0);
            Arrays.fill(mc, 0);
            mc[0] = (1 << maxLetter) - 1;
            for (int i = 0; i < len; i++) {
                int letter = s[i];
                mc[count[letter]] &= ~(1 << letter);
                ++count[letter];
                mc[count[letter]] |= 1 << letter;
            }
            for (int i = 0; i + len <= s.length; i++) {
                if (len == s.length) {
                    for (int letter = 0; letter < maxLetter; letter++) {
                        int curMask = mc[count[letter]];
                        update(ansL, ansR, len, i, curMask);
                    }
                } else {
                    if (i > 0) {
                        int curMask = mc[count[s[i - 1]]];
                        update(ansL, ansR, len, i, curMask);
                    } else {
                        int curMask = mc[count[s[i + len]]];
                        update(ansL, ansR, len, i, curMask);
                    }
                }
                if (i + len < s.length) {
                    {
                        int letter = s[i];
                        mc[count[letter]] &= ~(1 << letter);
                        --count[letter];
                        mc[count[letter]] |= 1 << letter;
                    }
                    {
                        int letter = s[i + len];
                        mc[count[letter]] &= ~(1 << letter);
                        ++count[letter];
                        mc[count[letter]] |= 1 << letter;
                    }
                }
            }
        }
        for (int i = (1 << maxLetter) - 1; i >= 0; i--) {
            for (int j = 0; j < maxLetter; j++) {
                if (((i >> j) & 1) == 1) continue;
                int ni = i | (1 << j);
                if (ansL[ni] < 0) continue;
                if (ansL[i] < 0 || ansR[ni] - ansL[ni] > ansR[i] - ansL[i]) {
                    ansL[i] = ansL[ni];
                    ansR[i] = ansR[ni];
                }
            }
        }
        for (int i = 0; i < n; i++) {
            int id = qs[i];
            if (ansL[id] < 0) {
                out.println(-1);
            } else {
                out.println((ansL[id] + 1) + " " + (ansR[id] + 1));
            }
        }
    }

    private static void update(int[] ansL, int[] ansR, int len, int i, int curMask) {
        if (ansL[curMask] < 0) {
            ansL[curMask] = i;
            ansR[curMask] = i + len - 1;
        }
    }

    static StringTokenizer tokenizer;
    static BufferedReader reader;
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new FileReader("diamonds.in"));
        out = new PrintWriter("diamonds.out");
        solve();
        out.close();
        reader.close();
    }

    static String next() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            String line = reader.readLine();
            if (line == null) {
                return null;
            }
            tokenizer = new StringTokenizer(line);
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}
