#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e5 + 5;
int N, Q, M, dp[NMAX][30];
char ch, S[NMAX];
int Ap[30];
inline void Read() {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> ch;
    int X = ch - 'a';
    for (int j = 0; j <= ('z' - 'a'); ++j) dp[i][j] = dp[i - 1][j] + (j == X);
  }
  return;
}
inline bool Ok(int j) {
  for (int i = 0; i <= ('z' - 'a'); ++i)
    if (dp[j][i] >= Ap[i])
      continue;
    else
      return false;
  return true;
}
inline void Query() {
  int ans = 0, Left = 1, Right = N;
  while (Left <= Right) {
    int Mid = (Left + Right) / 2;
    if (Ok(Mid)) {
      ans = Mid;
      Right = Mid - 1;
    } else
      Left = Mid + 1;
  }
  cout << ans << '\n';
  return;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  Read();
  cin >> Q;
  while (Q--) {
    cin >> (S + 1);
    M = (int)strlen(S + 1);
    memset(Ap, 0, sizeof(Ap));
    for (int i = 1; i <= M; ++i) ++Ap[S[i] - 'a'];
    Query();
  }
  return 0;
}
