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

public class diamonds_av_wa {

	final int ALPH = 21;
	final String consonants = "bcdfghjklmnpqrstvwxyz";
	
	public void fix(char[] c) {
		for (int i = 0; i < c.length; i++) {
			c[i] = (char) ('a' + consonants.indexOf(c[i]));
		}
	}
	
	public void solve() {
		int n = in.nextInt();
		char[] c = in.nextToken().toCharArray();
		fix(c);
		int q = in.nextInt();

		int[] bestL = new int[1 << ALPH], bestR = new int[1 << ALPH];
		Arrays.fill(bestL, -1);
		Arrays.fill(bestR, -1);

		for (int i = 0; i < n; i++) {
			int[] count = new int[ALPH];
			int[] masks = new int[n + 1];
			masks[0] = (1 << ALPH) - 1;

			for (int j = i; j < n; j++) {
				int ch = c[j] - 'a';

				int checkMask = masks[count[ch]];
				if (j > i
						&& (bestL[checkMask] == -1 || bestR[checkMask]
								- bestL[checkMask] < j - 1 - i)) {
					bestR[checkMask] = j - 1;
					bestL[checkMask] = i;
				}

				masks[count[ch]] ^= 1 << ch;
				count[ch]++;
				masks[count[ch]] ^= 1 << ch;

				checkMask = masks[count[ch]];
				if (bestL[checkMask] == -1
						|| bestR[checkMask] - bestL[checkMask] < j - i) {
					bestR[checkMask] = j;
					bestL[checkMask] = i;
				}

			}

			for (int cnt = 0; cnt <= n - i; cnt++) {
				int checkMask = masks[cnt];
				if (bestL[checkMask] == -1
						|| bestR[checkMask] - bestL[checkMask] < n - 1 - i) {
					bestR[checkMask] = n - 1;
					bestL[checkMask] = i;
				}
			}
		}

//		for (int mask = bestL.length - 1; mask > 0; mask--) {
//			if (bestL[mask] == -1) {
//				continue;
//			}
//
//			for (int bit = 0; bit < ALPH; bit++) {
//				if ((mask & (1 << bit)) != 0) {
//					int newMask = mask ^ (1 << bit);
//					if (bestL[newMask] == -1
//							|| bestR[newMask] - bestL[newMask] < bestR[mask]
//									- bestL[mask]) {
//						bestR[newMask] = bestR[mask];
//						bestL[newMask] = bestL[mask];
//					}
//				}
//			}
//		}

		for (int i = 0; i < q; i++) {
			in.nextInt();
			char[] query = in.nextToken().toCharArray();
			fix(query);
			int mask = 0;
			for (int j = 0; j < query.length; j++) {
				mask |= 1 << (query[j] - 'a');
			}
			if (bestL[mask] == -1) {
				out.println(-1);
			} else {
				out.println((bestL[mask] + 1) + " " + (bestR[mask] + 1));
			}
		}
	}

	FastScanner in;
	PrintWriter out;

	public void run() {
		try {
			in = new FastScanner("diamonds.in");
			out = new PrintWriter("diamonds.out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String name) {
			try {
				br = new BufferedReader(new FileReader(name));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new diamonds_av_wa().run();
	}
}
