#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int MN = 200111;
char s[MN], a[MN];
int Left[30][MN], Right[30][MN], k;
void init() {
  memset(Left, -1, sizeof Left);
  memset(Right, -1, sizeof Right);
  for (int i = 0, _a = (k); i < _a; i++)
    if (i) {
      for (int c = 0, _a = (30); c < _a; c++) {
        Left[c][i] = Left[c][i - 1];
        if (s[i - 1] - 'a' == c) Left[c][i] = i - 1;
      }
    }
  for (int i = (k - 2), _b = (0); i >= _b; i--) {
    for (int c = 0, _a = (30); c < _a; c++) {
      Right[c][i] = Right[c][i + 1];
      if (s[i + 1] - 'a' == c) Right[c][i] = i + 1;
    }
  }
}
int ab(int x) {
  if (x < 0)
    return -x;
  else
    return x;
}
int main() {
  int n;
  scanf("%d %d\n", &n, &k);
  gets(s);
  init();
  while (n--) {
    gets(a);
    int l = strlen(a);
    long long sum = 0;
    int j, u, v, ii;
    for (int i = 0, _a = (l); i < _a; i++) {
      if (a[i] == s[i])
        sum += 0;
      else {
        ii = i;
        if (ii >= k) ii = k - 1;
        if (a[i] == s[ii])
          sum += ab(i - ii);
        else {
          u = Left[a[i] - 'a'][ii];
          v = Right[a[i] - 'a'][ii];
          if (u == -1 && v == -1)
            sum += l;
          else if (u == -1)
            sum += ab(v - i);
          else if (v == -1)
            sum += ab(u - i);
          else
            sum += min(ab(v - i), ab(u - i));
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}
