#include <bits/stdc++.h>
using namespace std;
vector<long long> a[26];
char h;
int n, k;
string s;
long long res;
long long ABS(long long x) {
  if (x < 0) x = -x;
  return x;
}
long long bin_search(int u, int x) {
  int l = 0, r = a[u].size() - 1, m = 0;
  if (r == 0) return s.length();
  while (l < r) {
    m = (l + r + 1) / 2;
    if (a[u][m] > x)
      r = m - 1;
    else
      l = m;
  }
  long long ret = 1000000000;
  if (l > 0) ret = ABS(x - a[u][l - 1]);
  if (l + 1 < a[u].size()) ret = min(ret, ABS(a[u][l + 1] - x));
  ret = min(ret, ABS(a[u][l] - x));
  return ret;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> h;
    a[h - 'a'].push_back(i);
  }
  for (int i = 0; i < 26; i++) a[i].push_back(1000000000);
  for (int i = 0; i < n; i++) {
    cin >> s;
    res = 0;
    for (int j = 0; j < s.length(); j++) res += bin_search(s[j] - 'a', j);
    cout << res << endl;
  }
}
