#include <bits/stdc++.h>
using namespace std;
string now, st;
vector<int> num[26];
int main(void) {
  int n, k;
  cin >> n >> k;
  cin >> st;
  for (int i = 0; i < (k); i++) {
    num[st[i] - 'a'].push_back(i);
  }
  for (int Case = 0; Case < (n); Case++) {
    cin >> now;
    long long res = 0;
    int len = now.size();
    for (int i = 0; i < (len); i++) {
      if (i >= k || st[i] != now[i]) {
        int alpha = now[i] - 'a';
        if (num[alpha].empty()) {
          res += len;
          continue;
        }
        int left = 0, right = num[alpha].size() - 1, mid;
        while (left < right) {
          mid = (left + right + 1) >> 1;
          if (num[alpha][mid] <= i)
            left = mid;
          else
            right = mid - 1;
        }
        int tmp = abs(i - num[alpha][left]);
        if (left + 1 < num[alpha].size())
          tmp = min(tmp, abs(i - num[alpha][left + 1]));
        res += tmp;
      }
    }
    cout << res << endl;
  }
}
