#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
int n, k;
char s[1000005];
char t[1000005];
vector<int> app[128];
int main() {
  int i;
  long long ans;
  int tmp, len;
  vector<int>::iterator it;
  cin >> n >> k;
  cin >> s;
  k = strlen(s);
  for (i = 0; i < k; i++) {
    app[(int)s[i]].push_back(i);
  }
  while (n--) {
    cin >> t;
    ans = 0LL;
    len = strlen(t);
    for (i = 0; i < len; i++) {
      if (((int)((app[(int)t[i]]).size())) == 0)
        ans += len;
      else {
        tmp = 1000000005;
        it = upper_bound(app[(int)t[i]].begin(), app[(int)t[i]].end(), i);
        if (it != app[(int)t[i]].end()) tmp = min(tmp, abs(i - *it));
        if (it != app[(int)t[i]].begin()) {
          --it;
          tmp = min(tmp, abs(i - *it));
        }
        it = lower_bound(app[(int)t[i]].begin(), app[(int)t[i]].end(), i);
        if (it != app[(int)t[i]].end()) tmp = min(tmp, abs(i - *it));
        if (it != app[(int)t[i]].begin()) {
          --it;
          tmp = min(tmp, abs(i - *it));
        }
        ans += tmp;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
