#include <bits/stdc++.h>
using namespace std;
string t, u;
int n, k;
char s[210000];
vector<vector<int> > a;
long long int st(string b) {
  long long int g(0);
  int p, q, r;
  for (int i = 0; i < b.size(); i++) {
    if (a[b[i] - 'a'].size() == 0)
      g += b.size();
    else {
      p = 0;
      q = a[b[i] - 'a'].size() - 1;
      while (q - p > 1) {
        r = (p + q) / 2;
        if (a[b[i] - 'a'][r] <= i)
          p = r;
        else
          q = r;
      }
      g += min(abs(i - a[b[i] - 'a'][p]), abs(i - a[b[i] - 'a'][q]));
    }
  }
  return g;
}
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", s);
  t = s;
  a.resize(26);
  for (int i = 0; i < 26; i++) a[i].resize(0);
  for (int i = 0; i < t.size(); i++) a[t[i] - 'a'].push_back(i);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    u = s;
    printf("%lld\n", st(u));
  }
  return 0;
}
