#include <bits/stdc++.h>
int diri[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dirj[] = {0, 1, 0, -1, 1, 1, -1, -1};
int compare(double d1, double d2) {
  if (fabs(d1 - d2) < 1e-9) return 0;
  if (d1 < d2) return -1;
  return 1;
}
using namespace std;
string base, s;
bool valid(int i, vector<int> v) { return i >= 0 && i < v.size(); }
int main() {
  int n, m;
  cin >> n >> m;
  cin >> base;
  vector<vector<int> > chInd(26);
  for (int j = 0; j < (int)base.size(); j++) chInd[base[j] - 'a'].push_back(j);
  for (int i = 0; i < (int)n; i++) {
    cin >> s;
    long long ans = 0;
    for (int j = 0; j < (int)s.size(); j++) {
      int c = s[j] - 'a';
      int ind =
          lower_bound(chInd[c].begin(), chInd[c].end(), j) - chInd[c].begin();
      int mn = chInd[c].size() ? ((int)1e20) : s.size();
      mn = (valid(ind, chInd[c])) ? min(mn, abs(chInd[c][ind] - j)) : mn;
      mn =
          (valid(ind - 1, chInd[c])) ? min(mn, abs(chInd[c][ind - 1] - j)) : mn;
      ans += mn;
    }
    cout << ans << endl;
  }
  return 0;
}
