#include <bits/stdc++.h>
using namespace std;
vector<int> v[30];
string s[100010];
char aver[300010];
long long f(int p, int ch, int si) {
  int mi = 99999999;
  if (v[ch].size() == 0) return s[si].size();
  for (int i = 0; i < v[ch].size(); i++) mi = min(mi, abs(p - v[ch][i]));
  return mi;
}
int main() {
  long long n, k;
  cin >> n >> k;
  cin >> aver;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (long long i = 0; i < k; i++) v[aver[i] - 'a'].push_back(i);
  for (int i = 1; i <= n; i++) {
    long long F = 0;
    for (int j = 0; j < s[i].size(); j++) {
      if (s[i][j] != aver[j]) {
        F += f(j, s[i][j] - 'a', i);
      }
    }
    cout << F << endl;
  }
}
