#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200007;
const int MAXT = 2139062143;
int i, j, k, n, m, t, x, y;
int rec[26][MAXN];
long long ans;
char c[MAXN];
int binarySearch(int a, int k, int mx) {
  int i, j, dif, l, r, m;
  dif = MAXT;
  if (rec[a][0] == 0) {
    return mx;
  }
  l = 0;
  r = rec[a][0] + 1;
  while (r - l > 1) {
    m = (l + r) / 2;
    if (rec[a][m] == k) {
      return 0;
    } else {
      if (rec[a][m] < k) {
        l = m;
      } else {
        r = m;
      }
    }
  }
  if (l > 0 && abs(k - rec[a][l]) < dif) {
    dif = abs(k - rec[a][l]);
  }
  if (r <= rec[a][0] && abs(rec[a][r] - k) < dif) {
    dif = abs(rec[a][r] - k);
  }
  return dif;
}
int main() {
  while (~scanf("%d%d", &n, &k)) {
    memset(rec, 0, sizeof(rec));
    scanf("%s", &c);
    for (i = 0; i < k; i++) {
      t = c[i] - 'a';
      rec[t][++rec[t][0]] = i;
    }
    for (i = 0; i < n; i++) {
      scanf("%s", &c);
      m = strlen(c);
      ans = 0;
      for (j = 0; j < m; j++) {
        t = c[j] - 'a';
        x = binarySearch(t, j, m);
        ans += x;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
