#include <bits/stdc++.h>
using namespace std;
int inf = (int)10e7;
vector<int> pos[26];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) pos[s[i] - 'a'].push_back(i);
  for (int i = 0; i < n; i++) {
    string f;
    cin >> f;
    long long int cur = 0;
    for (int t = 0; t < f.length(); t++) {
      int l, r;
      l = 0;
      r = pos[f[t] - 'a'].size() - 1;
      int maxl = -1, minm = inf;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (pos[f[t] - 'a'][mid] <= t) {
          maxl = max(maxl, pos[f[t] - 'a'][mid]);
          l = mid + 1;
        } else
          r = mid - 1;
      }
      l = 0;
      r = pos[f[t] - 'a'].size() - 1;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (pos[f[t] - 'a'][mid] >= t) {
          minm = min(minm, pos[f[t] - 'a'][mid]);
          r = mid - 1;
        } else
          l = mid + 1;
      }
      if (minm == inf && maxl == -1) {
        cur += f.length();
        continue;
      }
      int res = inf;
      if (minm != inf) res = min(res, minm - t);
      if (maxl != -1) res = min(res, t - maxl);
      cur += res;
    }
    cout << cur << "\n";
  }
}
