#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 2e5 + 10;
char str[N];
vector<int> v[N];
int main() {
  for (int i = 0; i < N; i++) v[i].push_back(-INF);
  int q, len;
  scanf("%d%d", &q, &len);
  scanf("%s", str + 1);
  for (int i = 1; i <= len; i++) {
    v[str[i]].push_back(i);
  }
  for (int i = 0; i < N; i++) v[i].push_back(INF);
  while (q--) {
    scanf("%s", str + 1);
    int m = strlen(str + 1);
    long long sum = 0;
    for (int i = 1; i <= m; i++) {
      if (v[str[i]].size() == 2) {
        sum += m;
        continue;
      }
      auto iter = upper_bound(v[str[i]].begin(), v[str[i]].end(), i);
      int r = *iter;
      iter--;
      int l = *iter;
      sum += min(i - l, r - i);
    }
    printf("%lld\n", sum);
  }
  return 0;
}
