#include <bits/stdc++.h>
using namespace std;
int n, k;
string s, mas[100010];
vector<int> v[26];
int main() {
  cin >> n >> k;
  cin >> s;
  for (int i = 0; i < n; i++) cin >> mas[i];
  for (int i = 0; i < (int)s.length(); i++) v[s[i] - 'a'].push_back(i);
  for (int i = 0; i < n; i++) {
    long long f = 0;
    for (int j = 0; j < (int)mas[i].length(); j++) {
      if ((int)v[mas[i][j] - 'a'].size() == 0)
        f += mas[i].length();
      else {
        int l = 0, r = v[mas[i][j] - 'a'].size();
        while (l != r - 1) {
          int mid = (l + r) / 2;
          if (v[mas[i][j] - 'a'][mid] <= j)
            l = mid;
          else
            r = mid;
        }
        int dist1 = abs(v[mas[i][j] - 'a'][l] - j);
        int dist2 = (l + 1 >= (int)v[mas[i][j] - 'a'].size())
                        ? 2000000
                        : abs(v[mas[i][j] - 'a'][l + 1] - j);
        f += min(dist1, dist2);
      }
    }
    cout << f << '\n';
  }
  return 0;
}
