#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int r = s.size();
  set<int> *tab = new set<int>[26];
  for (int j = 0; j < r; ++j) {
    tab[s[j] - 97].insert(j);
  }
  for (int i = 0; i < n; ++i) {
    string c;
    cin >> c;
    int z = c.size();
    long long int f = 0;
    for (int j = 0; j < z; ++j) {
      int zn = c[j] - 97;
      if (tab[zn].empty())
        f += z;
      else {
        int m = (1 << 25);
        if (*(tab[zn].begin()) >= j) m = *(tab[zn].begin()) - j;
        set<int>::iterator nast = tab[zn].end();
        --nast;
        if (*nast <= j) m = j - *nast;
        if (m == (1 << 25)) {
          set<int>::iterator akt = tab[zn].lower_bound(j);
          int p = *akt;
          int q = -(1 << 25);
          if (akt != tab[zn].begin()) {
            --akt;
            q = *akt;
          }
          m = min(p - j, j - q);
        }
        f += m;
      }
    }
    cout << f << "\n";
  }
  return 0;
}
