#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string t;
  cin >> t;
  vector<int> a[30];
  for (int i = 0; i < k; i++) {
    int c = t[i] - 'a';
    a[c].push_back(i);
  }
  for (int i = 0; i < 26; i++) sort(a[i].begin(), a[i].end());
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    long long f = 0;
    for (int j = 0; j < s.length(); j++)
      if (a[s[j] - 'a'].empty()) {
        f += int(s.length());
      } else {
        int l = 0;
        int r = int(a[s[j] - 'a'].size()) - 1;
        while (r - l > 1) {
          int mid = (r + l) / 2;
          if (a[s[j] - 'a'][mid] > j)
            r = mid;
          else
            l = mid;
        }
        f += min(abs(a[s[j] - 'a'][l] - j), abs(a[s[j] - 'a'][r] - j));
      }
    cout << f << endl;
  }
  return 0;
}
