#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
vector<int> ans;
vector<int> sp[30];
int find_bin(char ch, int poz) {
  int left = 0, right = sp[ch - 'a'].size() - 1;
  int w = ch - 'a';
  if (right == -1) return inf;
  int ans = 1 << 30;
  while (left <= right) {
    int mid = (left + right) / 2;
    ans = min(ans, abs(sp[w][mid] - poz));
    if (sp[w][mid] < poz)
      left = mid + 1;
    else if (sp[w][mid] > poz)
      right = mid - 1;
    else
      break;
  }
  return ans;
}
int main() {
  int n, k;
  string str;
  cin >> n >> k;
  cin >> str;
  for (int i = 0; i < str.size(); i++) sp[str[i] - 'a'].push_back(i);
  for (int i = 0; i < 30; i++) sort(sp[i].begin(), sp[i].end());
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long f = 0;
    for (int j = 0; j < s.size(); j++) {
      int tmp = find_bin(s[j], j);
      if (tmp == inf)
        f += (long long)s.size();
      else
        f += (long long)tmp;
    }
    cout << f << "\n";
  }
  return 0;
}
