#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> pos[26];
const int mxn = 200007;
char s[mxn];
char w[mxn];
int main(int argc, char** argv) {
  scanf("%d", &n);
  scanf("%d", &k);
  scanf("%s", s);
  for (int i = 0; i < k; i++) {
    pos[(s[i] - 'a')].push_back(i);
  }
  for (int wi = 0; wi < n; wi++) {
    scanf("%s", w);
    int len = strlen(w);
    long long ans = 0;
    for (int i = 0; i < len; i++) {
      int v = (w[i] - 'a');
      if (pos[v].size() == 0) {
        ans += len;
      } else {
        int q = lower_bound(pos[v].begin(), pos[v].end(), i) - pos[v].begin();
        int cur = INT_MAX;
        for (int z = max(0, q - 2); z < q + 2 && z < (int)pos[v].size(); z++) {
          cur = min(cur, abs(i - pos[v][z]));
        }
        ans += cur;
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
