#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  map<char, vector<int> > m;
  for (int j = 0; j < s.size(); j++) {
    m[s[j]].push_back(j);
  }
  for (int i = 0; i < n; i++) {
    string p;
    cin >> p;
    long long f = 0;
    for (int j = 0; j < p.size(); j++) {
      if (m.find(p[j]) == m.end()) {
        f += p.size();
        continue;
      }
      vector<int> v = m[p[j]];
      if (v[0] >= j) {
        f += v[0] - j;
        continue;
      }
      if (v[v.size() - 1] <= j) {
        f += j - v[v.size() - 1];
        continue;
      }
      if (binary_search(v.begin(), v.end(), j)) {
        continue;
      }
      vector<int>::iterator it1 = lower_bound(v.begin(), v.end(), j);
      vector<int>::iterator it2 = upper_bound(v.begin(), v.end(), j);
      it1--;
      if (it2 == v.end()) it2--;
      f += min(abs((*it1) - j), abs((*it2) - j));
    }
    cout << f << "\n";
  }
}
