#include <bits/stdc++.h>
using namespace std;
int MAXN = 1000000;
int main() {
  int n, k;
  cin >> n >> k;
  set<int> m[30];
  set<int>::iterator it;
  for (int i = 0; i < 30; i++) {
    m[i].insert(0);
    m[i].insert(MAXN);
  }
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) {
    char c = s[i];
    m[c - 'a'].insert(i + 1);
  }
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    long long int f = 0;
    for (int j = 0; j < t.size(); j++) {
      char c = t[j];
      it = m[c - 'a'].upper_bound(j + 1);
      int b = *it;
      it--;
      int a = *it;
      long long int cnt = MAXN;
      if (a != 0 and a != MAXN) cnt = min(cnt, (long long int)abs(j + 1 - a));
      if (b != 0 and b != MAXN) cnt = min(cnt, (long long int)abs(j + 1 - b));
      if (cnt == MAXN) cnt = t.size();
      f += cnt;
    }
    cout << f << endl;
  }
  return 0;
}
