#include <bits/stdc++.h>
using namespace std;
bool ex[1 << 8];
char s[1 << 19], t[1 << 19];
vector<int> v[1 << 8];
int ubsh(vector<int>& v, int pos) {
  int ret = 1 << 28, left = 0, right = v.size() - 1, mid;
  while (left <= right) {
    mid = (left + right) >> 1;
    if (v[mid] < pos)
      left = mid + 1;
    else {
      ret = min(ret, v[mid]);
      right = mid - 1;
    }
  }
  return ret;
}
int dbsh(vector<int>& v, int pos) {
  int ret = -(1 << 28), left = 0, right = v.size() - 1, mid;
  while (left <= right) {
    mid = (left + right) >> 1;
    if (v[mid] > pos)
      right = mid - 1;
    else {
      ret = max(ret, v[mid]);
      left = mid + 1;
    }
  }
  return ret;
}
long long cnt() {
  long long ret = 0;
  int i, len = strlen(t);
  for (i = 0; i < len; i++) {
    if (!ex[t[i]])
      ret = ret + len;
    else
      ret = ret + min(i - dbsh(v[t[i]], i), ubsh(v[t[i]], i) - i);
  }
  return ret;
}
int main() {
  int n, k, i;
  scanf("%d%d%s", &n, &k, s);
  for (i = 0; s[i]; i++) {
    v[s[i]].push_back(i);
    ex[s[i]] = 1;
  }
  while (n--) {
    scanf("%s", t);
    printf("%I64d\n", cnt());
  }
  return 0;
}
