#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 28;
const long long mod = 1LL;
vector<int> adj[30];
long long b_search(int val, int indx) {
  int lo, hi, mid;
  long long ans = 1e12;
  lo = 0;
  hi = (int)adj[indx].size() - 1;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (adj[indx][mid] == val) return 0;
    if (adj[indx][mid] < val)
      lo = mid + 1;
    else
      hi = mid - 1;
    ans = min(ans, (long long)abs(val - adj[indx][mid]));
  }
  return ans;
}
int main() {
  int n, k, i, j;
  long long l;
  string s, c;
  while (scanf("%d %d", &n, &k) == 2) {
    for (i = 0; i < 26; i++) adj[i].clear();
    cin >> s;
    for (i = 0; i < s.length(); i++) {
      adj[s[i] - 'a'].push_back(i);
    }
    while (n--) {
      l = 0;
      cin >> c;
      for (i = 0; i < c.length(); i++) {
        if ((int)adj[c[i] - 'a'].size() == 0)
          l += (int)c.size();
        else
          l += b_search(i, c[i] - 'a');
      }
      printf("%I64d\n", l);
    }
  }
  return 0;
}
