#include <bits/stdc++.h>
using namespace std;
set<int> S[26];
long long res[100005];
char s[100005], p[200005];
long long myabs(long long num) {
  if (num < 0)
    return -num;
  else
    return num;
}
int main() {
  int i, j, n, k;
  scanf("%d%d", &n, &k);
  scanf(" %s", s);
  for (i = 0; i < k; ++i) {
    S[s[i] - 97].insert(i + 1);
  }
  for (i = 1; i <= n; ++i) {
    scanf(" %s", p);
    int len = strlen(p);
    for (j = 0; j < len; ++j) {
      if (S[p[j] - 97].size() == 0) {
        res[i] += len;
        continue;
      }
      int a = 999999999, b = 999999999;
      set<int>::iterator it;
      it = S[p[j] - 97].upper_bound(j + 1);
      if (it != S[p[j] - 97].end()) a = myabs((long long)*it - (j + 1));
      if (it != S[p[j] - 97].begin()) {
        --it;
        b = myabs((long long)*it - (j + 1));
      }
      if (a < b)
        res[i] += a;
      else
        res[i] += b;
    }
  }
  for (i = 1; i <= n; ++i) printf("%I64d\n", res[i]);
  return 0;
}
