#include <bits/stdc++.h>
using namespace std;
vector<int> mp[26];
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < 26; i++) mp[i].clear();
  for (int i = 0; i < s.size(); i++) {
    mp[s[i] - 'a'].push_back(i);
  }
  char c[200200];
  vector<long long> ret(n, 0);
  for (int i = 0; i < n; i++) {
    scanf("%s", c);
    int tam = strlen(c);
    for (int j = 0; c[j]; j++) {
      if (mp[c[j] - 'a'].empty())
        ret[i] += tam;
      else {
        int pos = upper_bound(mp[c[j] - 'a'].begin(), mp[c[j] - 'a'].end(), j) -
                  mp[c[j] - 'a'].begin();
        int mi = mp[c[j] - 'a'][pos - 1];
        if (pos == mp[c[j] - 'a'].size()) {
          ret[i] += abs(mi - j);
        } else {
          ret[i] += min(abs(mi - j), abs(mp[c[j] - 'a'][pos] - j));
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ret[i] << endl;
  }
  return 0;
}
