#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  string s;
  cin >> n >> x >> s;
  vector<vector<int> > di(200);
  for (int i = 0; i < s.length(); ++i) {
    di[s[i]].push_back(i);
  }
  for (int i = 0; i < di.size(); ++i) sort(di[i].begin(), di[i].end());
  long long sum;
  char c;
  cin.get(c);
  for (int i = 0; i < n; ++i) {
    sum = 0;
    int j = 0, m = 0;
    for (j = 0; cin.get(c) && c != 10; ++j) {
      if (di[c].size() == 0) {
        ++m;
      } else {
        int q = lower_bound(di[c].begin(), di[c].end(), j) - di[c].begin();
        int mn = 1 << 31 - 1;
        for (int g = max(0, q - 1); g < min((int)di[c].size(), q + 2); ++g)
          mn = min(mn, abs(di[c][g] - j));
        sum += mn;
      }
    }
    cout << sum + (long long)(m)*j << endl;
  }
  return 0;
}
