#include <bits/stdc++.h>
int n, q;
char s[200010], t[200010];
int cnts[200010][30], cntt[30];
short check(int x) {
  int i;
  for (i = 0; i < 26; i++)
    if (cnts[x][i] < cntt[i]) return 0;
  return 1;
}
int work() {
  int i, head = 1, tail = n, mid;
  for (i = 0; i < 26; i++) cntt[i] = 0;
  for (i = 1; t[i]; i++) cntt[t[i] - 'a']++;
  while (head < tail) {
    mid = (head + tail) >> 1;
    if (check(mid))
      tail = mid;
    else
      head = mid + 1;
  }
  return head;
}
int main() {
  int i, j;
  scanf("%d%s%d", &n, s + 1, &q);
  for (i = 1; i <= n; i++) {
    cnts[i][s[i] - 'a']++;
    for (j = 0; j < 26; j++) cnts[i][j] += cnts[i - 1][j];
  }
  while (q--) {
    scanf("%s", t + 1);
    printf("%d\n", work());
  }
  return 0;
}
