#include <bits/stdc++.h>
using namespace std;
int dp[26][100 * 1000 + 10];
bool was[26];
int main() {
  string s;
  int n, k;
  cin >> n >> k;
  cin >> s;
  memset(dp, -1, sizeof(dp));
  for (int i = (0), _b(26); i < _b; ++i) was[i] = true;
  for (int i = (0), _b(k); i < _b; ++i) was[s[i] - 'a'] = false;
  for (int j = (0), _b(26); j < _b; ++j) {
    if (was[j]) continue;
    int count = k;
    for (int i = (0), _b(k); i < _b; ++i) {
      if (s[i] - 'a' == j) count = 0;
      dp[j][i] = count++;
    }
    for (int i = (k), _b(100 * 1000 + 5); i < _b; ++i) dp[j][i] = count++;
    count = k;
    for (int i = (k)-1, _b(0); i >= _b; --i) {
      if (s[i] - 'a' == j) count = 0;
      dp[j][i] = ((dp[j][i] <= count) ? dp[j][i] : count);
      ++count;
    }
  }
  while (n--) {
    long long res = 0;
    string st;
    cin >> st;
    for (int i = (0), _b(st.size()); i < _b; ++i) {
      if (was[st[i] - 'a'])
        res += st.size();
      else
        res += dp[st[i] - 'a'][i];
    }
    printf("%I64d\n", res);
  }
  return 0;
}
