#include <bits/stdc++.h>
int b1[100009][26];
int b2[100009][26];
int b[100009][26];
char original[100009];
char w[2 * 100009];
using namespace std;
int n, k;
int main(void) {
  scanf("%d%d", &n, &k);
  scanf(" %s", original);
  int len = strlen(original);
  int o = len;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j < 26; j++) {
      if (original[i] == 'a' + j)
        b1[i][j] = 0;
      else {
        if (i == 0)
          b1[i][j] = 0x3f3f3f3f;
        else
          b1[i][j] = b1[i - 1][j] + 1;
      }
    }
  }
  for (int i = len - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if (original[i] == 'a' + j)
        b2[i][j] = 0;
      else {
        if (i == len - 1)
          b2[i][j] = 0x3f3f3f3f;
        else
          b2[i][j] = b2[i + 1][j] + 1;
      }
    }
  }
  for (int i = 0; i < len; i++) {
    for (int j = 0; j < 26; j++) {
      b[i][j] = min(b1[i][j], b2[i][j]);
    }
  }
  while (n--) {
    scanf(" %s", w);
    int len = strlen(w);
    long long r = 0;
    for (int i = 0; i < len; i++) {
      if (i >= o) {
        if (b[o - 1][w[i] - 'a'] < 1000000) {
          r += (b[o - 1][w[i] - 'a'] + (i - (o - 1)));
        } else
          r += len;
        continue;
      }
      if (w[i] != original[i]) {
        if (b[i][w[i] - 'a'] < 1000000)
          r += b[i][w[i] - 'a'];
        else
          r += len;
      }
    }
    cout << r << endl;
  }
  return 0;
}
