#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
void initf() {}
using namespace std;
const int inf = (1 << 30);
vector<int> letters[26];
char s[1000 * 101];
char t[1000 * 201];
int n, K;
int sz[26];
int add;
int f(int x, int pos) {
  if (sz[x] == 0) return (add);
  int le = 0, ri = sz[x] - 1, e, ret = -1;
  while (le <= ri) {
    e = (le + ri) / 2;
    if (letters[x][e] >= pos) {
      ret = e;
      ri = e - 1;
    } else {
      le = e + 1;
    }
  }
  int best = inf;
  if (ret != -1) {
    best = min(best, abs(pos - letters[x][ret]));
    --ret;
    if (ret >= 0) best = min(best, abs(pos - letters[x][ret]));
  } else {
    ret = sz[x] - 1;
    if (ret >= 0) best = min(best, abs(pos - letters[x][ret]));
  }
  if (best == inf) best = add;
  return (best);
}
long long gogogo(int len) {
  add = len;
  long long ret = 0;
  for (int i = 0; i < (len); ++i) {
    int x = t[i] - 'a';
    int val = f(x, i);
    ret += (long long)val;
  }
  return (ret);
}
void solve() {
  scanf("%d%d\n", &n, &K);
  scanf("%s\n", s);
  for (int i = 0; i < (K); ++i) {
    int x = s[i] - 'a';
    letters[x].push_back(i);
  }
  for (int i = 0; i < (26); ++i) sz[i] = letters[i].size();
  while (n--) {
    scanf("%s\n", t);
    long long ret = 0;
    int len = strlen(t);
    ret = gogogo(len);
    printf("%I64d\n", ret);
  }
}
int main() {
  initf();
  solve();
  return (0);
}
