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

public class diamonds_av_sort {

	final int ALPH = 26;
	
	public void solve() {
		int n = in.nextInt();
		char[] c = in.nextToken().toCharArray();
		initHash(ALPH);

		int q = in.nextInt();
		Item[] items = new Item[n + 1];
		for (int i =0 ; i <= n; i++) {
			items[i] = new Item(0, 0);
		}
		
		for (int test = 0; test < q; test++) {
			int size = in.nextInt();
			char[] alph = in.nextToken().toCharArray();
			if (alph.length == 1) {
				out.println(1 + " " + n);
				continue;
			}
			
			int[] ids = getOrdering(alph);
			int[] diff = new int[size - 1];
			
			long curHash = 0;
			items[0].hash = curHash;
			items[0].pos = 0;
			
			int bestL = -1, bestR = -1;
			
			for (int i = 0; i < n; i++) {
				int cur = c[i] - 'a';
				if (ids[cur] >= 0) {
					int id = ids[cur];
					if (id < size - 1) {
						diff[id]--;
						curHash -= pow[id];
					}
					if (id - 1 >= 0) {
						diff[id - 1]++;
						curHash += pow[id - 1];
					}
				}
				
				items[i + 1].hash = curHash;
				items[i + 1].pos = i + 1;
			}
			
			Arrays.sort(items);
			for (int i = 0; i <= n; ) {
				int j = i + 1;
				while (j <= n && items[i].hash == items[j].hash) {
					j++;
				}
				
				if (i < j - 1) {
					int checkL = items[i].pos, checkR = items[j - 1].pos - 1;
					if (bestL == -1 || (checkR - checkL > bestR - bestL)) {
						bestL = checkL;
						bestR = checkR;
					}
				}
				i = j;
			}
			
			if (bestL == -1) {
				out.println(-1);
			} else {
				out.println((bestL + 1) + " " + (bestR + 1));
			}
		}
	}
	
	class Item implements Comparable<Item> {
		long hash;
		int pos;
		
		
		public Item(long hash, int pos) {
			super();
			this.hash = hash;
			this.pos = pos;
		}


		@Override
		public int compareTo(Item o) {
			if (hash != o.hash) {
				return Long.compare(hash, o.hash);
			}
			return pos - o.pos;
		}
	}

	private int[] getOrdering(char[] alph) {
		int[] result = new int[ALPH];
		Arrays.fill(result, -1);
		int count = 0;
		for (int i = 0; i < alph.length; i++) {
			result[alph[i] - 'a'] = count++;
		}
		return result;
	}

	private void initHash(int n) {
		pow = new long[n + 1];
		pow[0] = 1;
		for (int i = 1; i <= n; i++) {
			pow[i] = pow[i - 1] * p;
		}
	}

	final int p = 424243;
	long[] pow;

	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_sort().run();
	}
}
