#include <bits/stdc++.h>
using namespace std;
char cs[200061];
char ct[200061];
vector<int> a[26];
int N, K, n, m;
int geti(int v, int idx) {
  vector<int> &b = a[v];
  if (b.size() == 0) return -1;
  int l = 0, r = b.size() - 1;
  while (l <= r) {
    if (l + 3 > r) {
      l -= 2;
      r += 2;
      l = max(l, 0);
      r = min(r, (int)b.size() - 1);
      int ret = 1000000001;
      for (int i = (l); i < (int)(r + 1); i++) ret = min(ret, abs(b[i] - idx));
      return ret;
    }
    int mid = (l + r) / 2;
    if (b[mid] == idx) return 0;
    if (b[mid] < idx) l = mid + 1;
    if (b[mid] > idx) r = mid - 1;
  }
  return -1;
}
int main() {
  scanf("%d%d%s", &N, &K, cs);
  for (int i = (0); i < (int)(26); i++) a[i].clear();
  n = strlen(cs);
  for (int i = (0); i < (int)(n); i++) a[cs[i] - 'a'].push_back(i);
  for (int i = (0); i < (int)(26); i++) sort(a[i].begin(), a[i].end());
  for (int i = (0); i < (int)(N); i++) {
    scanf("%s", ct);
    m = strlen(ct);
    long long ans = 0;
    for (int j = (0); j < (int)(m); j++) {
      int t = geti(ct[j] - 'a', j);
      if (t < 0)
        ans += m;
      else
        ans += t;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
