#include <bits/stdc++.h>
using namespace std;
char str[200010];
char str2[200010];
int main() {
  int n, m;
  vector<int> V[1500];
  scanf("%d %d", &n, &m);
  scanf("%s", str);
  for (int i = 0; i < m; i++) {
    V[str[i] - 'a'].push_back(i);
  }
  int in;
  for (int j = 0; j < n; j++) {
    scanf("%s", str2);
    long long int ans = 0;
    int sz = strlen(str2);
    for (int i = 0; i < sz; i++)
      if (str[i] != str2[i]) {
        if (V[str2[i] - 'a'].size() == 0)
          ans += sz;
        else {
          in =
              lower_bound(V[str2[i] - 'a'].begin(), V[str2[i] - 'a'].end(), i) -
              V[str2[i] - 'a'].begin();
          if (V[str2[i] - 'a'].size() == in) {
            ans += abs(i - V[str2[i] - 'a'][in - 1]);
          } else if (in) {
            ans += min(abs(i - V[str2[i] - 'a'][in - 1]),
                       abs(i - V[str2[i] - 'a'][in]));
          } else
            ans += (abs(i - V[str2[i] - 'a'][in]));
        }
      }
    printf("%lld\n", ans);
  }
  return 0;
}
