#include <bits/stdc++.h>
using namespace std;
vector<int> alpha[30];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  string s;
  cin >> n >> k >> s;
  for (int i = 0; i < k; ++i) alpha[s[i] - 'a'].push_back(i);
  while (n--) {
    long long res = 0;
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
      int cur = s[i] - 'a';
      if (!alpha[cur].size())
        res += s.length();
      else if (alpha[cur].size() == 1)
        res += abs(alpha[cur][0] - i);
      else {
        auto pos = lower_bound(alpha[cur].begin(), alpha[cur].end(), i);
        if (pos == alpha[cur].begin())
          res += abs(*pos - i);
        else
          res += min(abs(*pos - i), abs(*(prev(pos)) - i));
      }
    }
    cout << res << '\n';
  }
  return 0;
}
