#include <bits/stdc++.h>
using namespace std;
long long int n, l, F;
string user, poten;
vector<long long int> v[32];
bool f[32];
int main() {
  long long int i, ul, tm, ub;
  cin >> n >> l;
  cin >> user;
  for (i = 0; i < l; i++) {
    v[user[i] - 'a'].push_back(i);
    f[user[i] - 'a'] = 1;
  }
  while (n--) {
    F = 0;
    cin >> poten;
    ul = poten.length();
    for (i = 0; i < ul; i++) {
      if (f[poten[i] - 'a'] == 0) {
        F += ul;
      } else {
        ub =
            upper_bound(v[poten[i] - 'a'].begin(), v[poten[i] - 'a'].end(), i) -
            v[poten[i] - 'a'].begin();
        if (ub == 0) {
          tm = v[poten[i] - 'a'][ub] - i;
        } else if (ub == v[poten[i] - 'a'].size()) {
          tm = i - v[poten[i] - 'a'][ub - 1];
        } else {
          tm = min(v[poten[i] - 'a'][ub] - i, i - v[poten[i] - 'a'][ub - 1]);
        }
        F += tm;
      }
    }
    cout << F << '\n';
  }
  return 0;
}
