#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string s, A("a");
  cin >> s;
  vector<vector<int> > a(26);
  for (int i = 0; i < k; i++) a[s[i] - A[0]].push_back(i);
  for (int i = 0; i < n; i++) {
    cin >> s;
    long long ans = 0;
    for (int j = 0; j < s.size(); j++) {
      int b = (int)s[j] - A[0];
      int r = (int)a[b].size();
      if (r == 0)
        ans += s.size();
      else {
        r--;
        int l = 0;
        while (r - l > 1) {
          int m = (l + r) / 2;
          if (a[b][m] >= j)
            r = m;
          else
            l = m;
        }
        ans += min(abs(a[b][l] - j), abs(a[b][r] - j));
      }
    }
    cout << ans << endl;
  }
  return 0;
}
