#include <bits/stdc++.h>
using namespace std;
vector<int> alpha[26];
int n, m;
string s;
int main() {
  cin >> n >> m;
  cin >> s;
  for (int i = 0; i < m; i++) alpha[s[i] - 'a'].push_back(i);
  for (int i = 0; i < n; i++) {
    cin >> s;
    long long cost = 0;
    for (int i = 0; i < s.size(); i++) {
      if (alpha[s[i] - 'a'].size() == 0) {
        cost += s.size();
        continue;
      }
      int lb = 0, ub = alpha[s[i] - 'a'].size() - 1, now;
      while (lb < ub - 1) {
        int mid = (lb + ub) / 2;
        if (alpha[s[i] - 'a'][mid] > i)
          ub = mid;
        else
          lb = mid;
      }
      now = ub;
      if (ub < 0) now = 0;
      if (now - 1 == -1)
        cost += abs(i - alpha[s[i] - 'a'][now]);
      else
        cost += min(abs(alpha[s[i] - 'a'][now - 1] - i),
                    abs(i - alpha[s[i] - 'a'][now]));
    }
    cout << cost << endl;
  }
  return 0;
}
