#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, temp, len;
  long long int ans;
  string s, c;
  vector<int> pos[26];
  vector<int>::iterator u;
  cin >> n >> k >> s;
  for (int i = 0; i < k; i++) pos[s[i] - 'a'].push_back(i);
  for (int i = 0; i < n; i++) {
    ans = 0;
    cin >> c;
    len = (int)c.size();
    for (int j = 0; j < len; j++) {
      if (pos[c[j] - 'a'].empty())
        ans += len;
      else {
        u = lower_bound(pos[c[j] - 'a'].begin(), pos[c[j] - 'a'].end(), j);
        if (u == pos[c[j] - 'a'].end()) {
          u--;
          ans += j - *u;
        } else if (u == pos[c[j] - 'a'].begin())
          ans += *u - j;
        else {
          temp = *u - j;
          u--;
          temp = min(temp, j - *u);
          ans += temp;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
