#include <bits/stdc++.h>
int length;
int L[400004][26];
int R[26];
char line[400003];
char next[400003];
int min(int a, int b) { return a < b ? a : b; }
int main() {
  long long sol = 0;
  int n, x, w, z, t, len;
  scanf("%d %d", &n, &length);
  scanf("%s", line);
  for (z = 0; z < 26; z++) L[400002][z] = (1 << 28);
  for (w = 400001; w >= 0; w--) {
    for (z = 0; z < 26; z++) {
      L[w][z] = L[w + 1][z];
    }
    if (w < length) L[w][line[w] - 'a'] = w;
  }
  for (x = 0; x < n; x++) {
    sol = 0;
    scanf("%s", next);
    memset(R, -1, sizeof(R));
    len = strlen(next);
    for (w = 0; w < len; w++) {
      if (w < length) R[line[w] - 'a'] = w;
      if (L[w][next[w] - 'a'] == (1 << 28) && R[next[w] - 'a'] == -1) {
        sol += len;
      } else {
        t = (1 << 28);
        if (R[next[w] - 'a'] != -1) t = min(w - R[next[w] - 'a'], t);
        if (w < length && L[w][next[w] - 'a'] != (1 << 28))
          t = min(L[w][next[w] - 'a'] - w, t);
        sol += t;
      }
    }
    printf("%I64d\n", sol);
  }
  return 0;
}
