#include <bits/stdc++.h>
using namespace std;
vector<int> pos[256];
string s;
int main() {
  int n, k;
  cin >> n >> k;
  cin >> s;
  for (int i = 0; i < s.size(); i++) pos[s[i]].push_back(i);
  for (int i = 0; i < n; i++) {
    cin >> s;
    long long f = 0;
    for (int j = 0; j < s.size(); j++) {
      int l = 0, r = pos[s[j]].size();
      if (!r)
        f += s.size();
      else {
        while (l + 1 < r) {
          int mid = (l + r) / 2;
          if (pos[s[j]][mid] > j)
            r = mid;
          else
            l = mid;
        }
        int res = int(1e9);
        if (r < pos[s[j]].size()) res = abs(j - pos[s[j]][r]);
        res = min(abs(j - pos[s[j]][l]), res);
        f += res;
      }
    }
    cout << f << endl;
  }
  return 0;
}
