#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int NMAX = 2e5 + 2;
vector<vector<int>> memos(NMAX, vector<int>(26, 0));
vector<int> memot(26, 0);
string s, t;
int n, m;
bool valid(int mid) {
  for (int i = 0; i < 26; ++i) {
    if (memos[mid][i] < memot[i]) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  cin >> s;
  int q;
  cin >> q;
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      memos[0][s[i] - 'a']++;
      continue;
    }
    memos[i] = memos[i - 1];
    memos[i][s[i] - 'a']++;
  }
  while (q--) {
    cin >> t;
    m = (int)t.size();
    memot.assign(26, 0);
    for (int i = 0; i < m; ++i) {
      memot[t[i] - 'a']++;
    }
    int l = 0, r = n - 1, ans;
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if (valid(mid)) {
        r = mid - 1;
        ans = mid;
      } else {
        l = mid + 1;
      }
    }
    cout << ans + 1 << endl;
  }
  return 0;
}
