#include <bits/stdc++.h>
using namespace std;
double pi = 3.14159265358979323846264338;
const int MOD = 1000000007;
int ind = 0;
int cnt = 1;
int arr3[27][200004];
char s[1001000], s2[2000100];
vector<int> arr[27];
int arr2[27];
int n, lnth;
inline int ab(int a, int b) { return (int)(abs(b - a) + 0.000001); }
int de(int a, int b) {
  int l = 0, r = arr[a].size() - 1;
  int k = 0;
  int t = 1000000000;
  if (r == -1) return t;
  while (r > l) {
    int m = (l + r) / 2;
    if (arr[a][m] < b) l = m + 1;
    if (arr[a][m] >= b) r = m - 1;
  }
  if (arr[a][l] >= b)
    k = l;
  else
    k = l + 1;
  if (arr[a][0] >= b) k = 0;
  for (int i = 0; i >= -1; i--) {
    if (k + i >= arr[a].size()) continue;
    t = min(t, ab(b, arr[a][k + i]));
  }
  return t;
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d%d%s", &n, &lnth, s);
  for (int i = 0; i < lnth; i++) {
    arr[s[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", &s2);
    int lnth2 = strlen(s2);
    long long ans = 0;
    for (int j = 0; j < lnth2; j++) {
      int k = s2[j] - 'a';
      int v = de(k, j);
      if (v == 1000000000)
        ans += lnth2;
      else
        ans += v;
    }
    cout << ans << endl;
  }
  return 0;
}
