#include <bits/stdc++.h>
using namespace std;
const int N = 2000006;
char s[N];
int idx[N][26];
int main() {
  int n, k;
  scanf("%d %d %s", &n, &k, s);
  int closest[26];
  memset(closest, -1, sizeof closest);
  for (int i = 0; i < N; ++i) {
    closest[s[i] - 'a'] = i;
    for (int j = 0; j < 26; ++j) idx[i][j] = closest[j];
  }
  memset(closest, -1, sizeof closest);
  for (int i = N - 1; i >= 0; --i) {
    closest[s[i] - 'a'] = i;
    for (int j = 0; j < 26; ++j) {
      if (idx[i][j] == -1 ||
          (closest[j] != -1 && abs(i - closest[j]) < abs(i - idx[i][j])))
        idx[i][j] = closest[j];
    }
  }
  while (n--) {
    long long res = 0;
    scanf("%s", s);
    k = strlen(s);
    for (int i = 0; i < k; ++i) {
      res += idx[i][s[i] - 'a'] == -1 ? k : abs(i - idx[i][s[i] - 'a']);
    }
    printf("%I64d\n", res);
  }
}
