#include <bits/stdc++.h>
using namespace std;
int a[26][100005];
int b[26];
string s, t;
int n, m, l, r;
int cnt(char c, int i) {
  if (b[int(c - 'a')] == 0)
    return t.size();
  else {
    l = 1, r = b[int(c - 'a')];
    while (l < r) {
      int mid = (l + r) / 2;
      if (a[int(c - 'a')][mid] > i)
        r = mid - 1;
      else if (a[int(c - 'a')][mid] < i)
        l = mid + 1;
      else
        return 0;
    }
  }
  int x = abs(a[int(c - 'a')][l] - i);
  if (x > abs(a[int(c - 'a')][max(l - 1, 1)] - i))
    x = abs(a[int(c - 'a')][l - 1] - i);
  if (x > abs(a[int(c - 'a')][min(l + 1, b[int(c - 'a')])] - i))
    x = abs(a[int(c - 'a')][l + 1] - i);
  return x;
}
int main() {
  cin >> n >> m;
  cin >> s;
  for (int i = 0; i < m; i++) {
    a[int(s[i] - 'a')][b[int(s[i] - 'a')] + 1] = i, b[int(s[i] - 'a')]++;
  }
  while (n--) {
    cin >> t;
    long long res = 0;
    for (int j = 0; j < t.size(); j++) res += cnt(t[j], j);
    printf("%I64d\n", res);
  }
  return 0;
}
