#include <bits/stdc++.h>
using namespace std;
int N, K, L, cur[26], D[200000][26];
long long int ans;
string A;
int main() {
  memset(D, -1, sizeof(D));
  scanf("%d%d", &N, &K);
  cin >> A;
  memset(cur, -1, sizeof(cur));
  for (int i = 0; i < K; ++i) {
    cur[A[i] - 'a'] = i;
    for (int j = 0; j < 26; ++j) D[i][j] = cur[j];
  }
  for (int i = K; i < 200000; ++i)
    for (int j = 0; j < 26; ++j) D[i][j] = cur[j];
  memset(cur, -1, sizeof(cur));
  for (int i = K - 1; i >= 0; --i) {
    cur[A[i] - 'a'] = i;
    for (int j = 0; j < 26; ++j)
      if (cur[j] != -1 && (D[i][j] == -1 || cur[j] - i < i - D[i][j]))
        D[i][j] = cur[j];
  }
  for (int a = 0; a < N; ++a) {
    cin >> A;
    ans = 0;
    L = A.size();
    for (int i = 0; i < L; ++i) {
      if (D[i][A[i] - 'a'] == -1)
        ans += (long long int)(L);
      else
        ans += (long long int)(abs(i - D[i][A[i] - 'a']));
    }
    cout << ans << endl;
  }
}
