#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int TT = clock();
  long long int n;
  cin >> n;
  vector<vector<long long int>> a(n);
  string s;
  cin >> s;
  vector<long long int> b(26);
  for (long long int i = 0; i < n; i++) {
    b[s[i] - 'a']++;
    a[i] = b;
  }
  long long int q;
  cin >> q;
  while (q--) {
    vector<long long int> c(26);
    string rr;
    cin >> rr;
    for (char cc : rr) c[cc - 'a']++;
    long long int l = 0, r = n;
    while (l < r) {
      long long int mid = (l + r) / 2;
      bool ok = true;
      vector<long long int> d = c;
      for (long long int i = 0; i < 26; i++) {
        d[i] -= a[mid][i];
      }
      for (long long int i = 0; i < 26; i++) {
        if (d[i] > 0) ok = false;
      }
      if (ok)
        r = mid;
      else
        l = mid + 1;
    }
    cout << l + 1 << "\n";
  }
  cerr << "\n\nTIME: " << (long double)(clock() - TT) / CLOCKS_PER_SEC
       << " sec\n";
  TT = clock();
  return 0;
}
