#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, tmp, len;
  long long ans;
  string s, t;
  vector<long long> pos[30];
  vector<long long>::iterator it;
  cin >> n >> k >> s;
  for (int i = 0; i < k; i++) pos[s[i] - 'a'].push_back(i);
  for (int i = 0; i < n; i++) {
    ans = 0;
    cin >> t;
    len = t.size();
    for (int j = 0; j < len; j++) {
      if (pos[t[j] - 'a'].empty())
        ans += len;
      else {
        it = lower_bound(pos[t[j] - 'a'].begin(), pos[t[j] - 'a'].end(), j);
        if (it == pos[t[j] - 'a'].end()) {
          it--;
          ;
          ans += abs(j - *it);
        } else if (it == pos[t[j] - 'a'].begin())
          ans += abs(j - *it);
        else {
          tmp = abs(*it - j);
          it--;
          tmp = min(tmp, abs(j - *it));
          ans += tmp;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
