#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100000;
const int INF = 1000000000;
const long double EPS = 1e-9;
int a[27][200000];
int sza[27];
char buf[200100];
int n, k;
int main() {
  scanf("%d %d\n", &n, &k);
  memset(sza, 0, sizeof sza);
  for (int i = 0; i < int(k); i++) {
    char c;
    scanf("%c", &c);
    a[c - 'a'][sza[c - 'a']++] = i;
  }
  scanf("\n");
  for (int i = 0; i < int(n); i++) {
    long long res = 0;
    gets(buf);
    int len = strlen(buf);
    for (int j = 0; j < int(len); j++) {
      int c = buf[j] - 'a';
      int idx = lower_bound(a[c], a[c] + sza[c], j) - a[c];
      if (sza[c] == 0)
        res += len;
      else {
        int mn = 1000 * 1000 * 1000;
        for (int g = max(0, idx - 4); g < min(sza[c], idx + 4); g++)
          mn = min(mn, abs(a[c][g] - j));
        res += mn;
      }
    }
    cout << res << endl;
  }
  return 0;
}
