#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int mod = 1000000007;
vector<int> vc[26];
vector<int>::iterator it;
char s[maxn * 2];
bool vis[26];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  scanf("%s", s);
  for (int i = 0; i < k; i++) {
    vc[s[i] - 'a'].push_back(i);
    vis[s[i] - 'a'] = 1;
  }
  long long ans;
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    ans = 0;
    int len = strlen(s), p;
    for (int j = 0; j < len; j++) {
      p = s[j] - 'a';
      if (!vis[p]) {
        ans += len;
        continue;
      }
      it = lower_bound(vc[p].begin(), vc[p].end(), j);
      if (it == vc[p].end()) {
        ans += j - *(it - 1);
      } else if (it == vc[p].begin()) {
        ans += (*it - j);
      } else {
        ans += min(*it - j, j - *(it - 1));
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
