#include <bits/stdc++.h>
using namespace std;
int k;
string s;
vector<vector<int> > v;
void MAKES() {
  v.resize(26);
  for (int i = 0; i < 26; i++) v[i].push_back(-1000000);
  for (int i = 0; i < s.size(); i++) v[s[i] - 'a'].push_back(i);
  for (int i = 0; i < 26; i++) v[i].push_back(1000000);
}
long long LD(int idx, int t) {
  int lo = 0, hi = v[t].size() - 1, md;
  while (lo != hi) {
    md = (lo + hi + 1) / 2;
    if (v[t][md] > idx)
      hi = md - 1;
    else
      lo = md;
  }
  return idx - v[t][lo];
}
long long HD(int idx, int t) {
  int lo = 0, hi = v[t].size() - 1, md;
  while (lo != hi) {
    md = (lo + hi) / 2;
    if (v[t][md] < idx)
      lo = md + 1;
    else
      hi = md;
  }
  return v[t][lo] - idx;
}
void SOLVE() {
  long long ret = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    int t = s[i] - 'a';
    if (v[t].size() == 2) {
      ret += s.size();
      continue;
    }
    ret += min(LD(i, t), HD(i, t));
  }
  cout << ret << endl;
}
int main() {
  int n;
  cin >> n >> k;
  cin >> s;
  MAKES();
  for (int i = 0; i < n; i++) SOLVE();
  return 0;
}
