#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, i, j;
  cin >> t >> n;
  string a;
  cin >> a;
  vector<set<int> > vr(26);
  for (i = 0; i < n; i++) {
    vr[a[i] - 'a'].insert(i);
  }
  while (t--) {
    string b;
    cin >> b;
    n = b.size();
    long long ans = 0;
    for (i = 0; i < n; i++) {
      auto it = vr[b[i] - 'a'].lower_bound(i);
      if (it == vr[b[i] - 'a'].end()) {
        if (vr[b[i] - 'a'].size()) {
          it--;
          ans += abs(i - *it);
        } else
          ans += n;
      } else {
        int x = *it;
        if (vr[b[i] - 'a'].begin() == it) {
          ans += abs(i - x);
        } else {
          it--;
          int y = *it;
          ans += min(abs(x - i), abs(y - i));
        }
      }
    }
    cout << ans;
    printf("\n");
  }
  return 0;
}
