#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, l;
string s, t;
int fr[N][26], frt[26];
bool can(int x) {
  for (int i = 0; i < 26; i++)
    if (fr[x][i] < frt[i]) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> l >> s >> n;
  for (int i = 0; i < l; i++) {
    fr[i + 1][s[i] - 'a']++;
    for (int j = 0; j < 26; j++) fr[i + 1][j] += fr[i][j];
  }
  while (n--) {
    cin >> t;
    memset(frt, 0, sizeof frt);
    for (int i = 0; i < t.length(); i++) frt[t[i] - 'a']++;
    int lo = 1, hi = l, ans = l;
    while (lo <= hi) {
      int md = (lo + hi) >> 1;
      if (can(md)) {
        ans = md;
        hi = md - 1;
      } else
        lo = md + 1;
    }
    cout << ans << '\n';
  }
  return 0;
}
