#include <bits/stdc++.h>
using namespace std;
void clr(long long&);
int find_max(vector<int>&, int);
int n;
int k;
string s;
string t;
vector<int> pos[26];
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  cin.ignore();
  getline(cin, s, '\n');
  long long f;
  for (int i = 0; i < (int)s.size(); ++i) {
    pos[s[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    getline(cin, t, '\n');
    f = 0;
    for (int j = 0; j < (int)t.size(); ++j) {
      if (pos[t[j] - 'a'].empty()) {
        f += (int)t.size();
      } else {
        f += find_max(pos[t[j] - 'a'], j);
      }
    }
    cout << f << "\n";
  }
  return EXIT_SUCCESS;
}
int find_max(vector<int>& a, int x) {
  int l = 0;
  int r = (int)a.size() - 1;
  int m;
  int result = INT_MAX;
  while (l < r) {
    m = (l + r) >> 1;
    if (a[m] >= x) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  result = min(result, abs(x - a[l]));
  if (l - 1 >= 0) {
    result = min(result, abs(x - a[l - 1]));
  }
  if (l + 1 < (int)a.size()) {
    result = min(result, abs(x - a[l + 1]));
  }
  l = 0;
  r = (int)a.size() - 1;
  while (l < r) {
    m = (l + r + 1) >> 1;
    if (a[m] <= x) {
      l = m;
    } else {
      r = m - 1;
    }
  }
  result = min(result, abs(x - a[l]));
  if (l - 1 >= 0) {
    result = min(result, abs(x - a[l - 1]));
  }
  if (l + 1 < (int)a.size()) {
    result = min(result, abs(x - a[l + 1]));
  }
  return result;
}
void clr(long long& F) {
  F = 0;
  for (int i = 0; i < 26; ++i) {
    pos[i].clear();
  }
}
