#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int N = (int)1e5 * 4;
const long long INF = (long long)1e18;
const double eps = (double)1e-6;
int n, m;
int used[27][N];
string s, a;
int d[27];
bool check(int x) {
  for (int i = 0; i < 27; ++i) {
    if (d[i] > used[i][x]) {
      return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> s;
  for (int i = 0; i < (long long)(s.size()); ++i) {
    used[s[i] - 'a'][i]++;
    for (int j = 0; j < 27; ++j) used[j][i] += used[j][i - 1];
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> a;
    for (int j = 0; j < (long long)(a.size()); ++j) {
      d[a[j] - 'a']++;
    }
    int l = -1, r = (long long)(s.size());
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (check(mid) && mid >= (long long)(a.size()) - 1)
        r = mid;
      else
        l = mid;
    }
    cout << r + 1 << endl;
    for (int j = 0; j < (long long)(a.size()); ++j) {
      d[a[j] - 'a'] = 0;
    }
  }
  return 0;
}
