#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN(200005);
char a[MAXN], b[MAXN];
vector<int> d[30];
int main() {
  int n, k, L;
  scanf("%d%d%s", &n, &k, a);
  L = strlen(a);
  for (int i = 0; i < L; i++) d[a[i] - 'a'].push_back(i);
  for (int i = 0; i < n; i++) {
    scanf("%s", b);
    int l = strlen(b);
    long long error = 0;
    for (int j = 0; j < l; j++) {
      int low = 0, high = d[b[j] - 'a'].size() - 1, mid, c1 = -INF;
      while (low <= high) {
        mid = (low + high) / 2;
        if (d[b[j] - 'a'][mid] <= j)
          c1 = mid, low = mid + 1;
        else
          high = mid - 1;
      }
      low = 0, high = d[b[j] - 'a'].size() - 1;
      int c2 = INF;
      while (low <= high) {
        mid = (low + high) / 2;
        if (d[b[j] - 'a'][mid] >= j)
          c2 = mid, high = mid - 1;
        else
          low = mid + 1;
      }
      if (c1 == -INF && c2 == INF)
        error += (long long)(l);
      else if (c1 == -INF)
        error += (long long)(d[b[j] - 'a'][c2] - j);
      else if (c2 == INF)
        error += (long long)(j - d[b[j] - 'a'][c1]);
      else
        error += (long long)(min(j - d[b[j] - 'a'][c1], d[b[j] - 'a'][c2] - j));
    }
    printf("%I64d\n", error);
  }
}
