#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
string s[100001];
vector<int> v[26];
int f[26];
int main() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) cin >> s[i];
  for (int j = 0; j < 26; j++) {
    v[j].clear();
    f[j] = 0;
  }
  for (int j = 0; j < ((int)(s[0]).size()); j++) v[s[0][j] - 'a'].push_back(j);
  for (int i = 1; i <= n; i++) {
    long long cur = 0;
    for (int j = 0; j < 26; j++) f[j] = 0;
    for (int j = 0; j < ((int)(s[i]).size()); j++) {
      int x = s[i][j] - 'a';
      if (v[x].empty())
        cur += ((int)(s[i]).size());
      else {
        while (f[x] + 1 < ((int)(v[x]).size()) && v[x][f[x] + 1] <= j) f[x]++;
        int tmp = abs(v[x][f[x]] - j);
        if (f[x] + 1 < ((int)(v[x]).size()))
          tmp = min(tmp, abs(v[x][f[x] + 1] - j));
        cur += tmp;
      }
    }
    printf("%I64d\n", cur);
  }
  return 0;
}
