#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, m, i, j, s, l, a[26], f[maxn][26];
char c[maxn];
int check() {
  int l, r, t, h;
  l = 0;
  r = s;
  while (l <= r) {
    t = (l + r) >> 1;
    h = 0;
    for (int i = 0; i < 26; i++)
      if (f[t][i] < a[i]) {
        h = 1;
        break;
      }
    if (h == 1)
      l = t + 1;
    else
      r = t - 1;
  }
  return l + 1;
}
int main() {
  scanf("%d", &n);
  scanf("%s", c);
  s = strlen(c) - 1;
  ++f[0][c[0] - 'a'];
  for (i = 1; i < n; i++) {
    for (j = 0; j < 26; j++) f[i][j] = f[i - 1][j];
    ++f[i][c[i] - 'a'];
  }
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%s", c);
    memset(a, 0, sizeof(a));
    l = strlen(c);
    for (j = 0; j < l; j++) ++a[c[j] - 'a'];
    printf("%d\n", check());
  }
  return 0;
}
