#include <bits/stdc++.h>
using namespace std;
int c[200100][26];
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  int n, m;
  string x, s;
  cin >> n >> x >> m;
  x = '0' + x;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) c[i][j] = c[i - 1][j];
    c[i][x[i] - 'a']++;
  }
  while (m--) {
    cin >> s;
    int y[26] = {};
    for (int i = 0; i < s.size(); i++) {
      y[s[i] - 'a']++;
    }
    int hi = n, lo = 1, best = n;
    while (hi >= lo) {
      bool ok = 1;
      int mid = (hi + lo) / 2;
      for (int i = 0; i < 26; i++) {
        if (c[mid][i] < y[i]) ok = 0;
      }
      if (ok) {
        hi = mid - 1;
        best = min(best, mid);
      } else
        lo = mid + 1;
    }
    cout << best << endl;
  }
  return 0;
}
