#include <bits/stdc++.h>
using namespace std;
int N, SZ;
char a[1 << 17];
char b[1 << 18];
int brl[1 << 17][27];
int brr[1 << 17][27];
void scan() {
  scanf("%d%d", &N, &SZ);
  scanf("%s", a);
}
void pre_calc() {
  memset(brl[0], -1, sizeof(brl[0]));
  brl[0][a[0] - 'a'] = 0;
  for (int i = 1; i < SZ; ++i) {
    for (int j = 0; j < 26; ++j)
      if (brl[i - 1][j] != -1)
        brl[i][j] = brl[i - 1][j] + 1;
      else
        brl[i][j] = -1;
    brl[i][a[i] - 'a'] = 0;
  }
  memset(brr[SZ - 1], -1, sizeof(brr[SZ - 1]));
  brr[SZ - 1][a[SZ - 1] - 'a'] = 0;
  for (int i = SZ - 2; i >= 0; --i) {
    for (int j = 0; j < 26; ++j)
      if (brr[i + 1][j] != -1)
        brr[i][j] = brr[i + 1][j] + 1;
      else
        brr[i][j] = -1;
    brr[i][a[i] - 'a'] = 0;
  }
}
inline int min(int t1, int t2) { return (t1 < t2) ? t1 : t2; }
long long calc() {
  long long res = 0;
  int cur_sz = strlen(b);
  for (int i = 0; i < cur_sz; ++i) {
    int idx = min(SZ - 1, i), add;
    add = i - idx;
    char ch = b[i] - 'a';
    if (brr[idx][ch] == -1 && brl[idx][ch] == -1)
      res += cur_sz;
    else if (brr[idx][ch] == -1)
      res += brl[idx][ch] + add;
    else if (brl[idx][ch] == -1)
      res += brr[idx][ch] + add;
    else
      res += min(brr[idx][ch], brl[idx][ch]) + add;
  }
  return res;
}
void solve() {
  pre_calc();
  for (int i = 0; i < N; ++i) {
    scanf("%s", b);
    printf("%I64d\n", calc());
  }
}
int main() {
  scan();
  solve();
}
