#include <bits/stdc++.h>
using namespace std;
int a[200004][26];
int n;
bool check(int m, vector<int>& v) {
  for (int i = 0; i < 26; i++) {
    if (v[i] == 0)
      continue;
    else if (v[i] > a[m][i])
      return false;
  }
  return true;
}
int fun(vector<int>& v) {
  int l = 0, r = n - 1;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (check(mid, v)) {
      r = mid;
    } else
      l = mid;
  }
  if (check(l, v)) return l;
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int m;
  string s;
  cin >> n >> s;
  a[0][s[0] - 'a']++;
  for (int i = 1; i < n; i++) {
    a[i][s[i] - 'a']++;
    for (int j = 0; j < 26; j++) a[i][j] += a[i - 1][j];
  }
  cin >> m;
  while (m--) {
    string temp;
    cin >> temp;
    vector<int> v(26, 0);
    for (int i = 0; i < (int)temp.size(); i++) v[temp[i] - 'a']++;
    cout << fun(v) + 1 << "\n";
  }
}
