#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100000 + 10;
const int INF = 0x7f7f7f7f;
const double eps = 1e-8;
char in[Maxn], tmp[2 * Maxn];
vector<int>::iterator vp;
map<int, vector<int> > mp;
map<int, vector<int> >::iterator ptr;
int main() {
  long long ans;
  int len, n, k;
  scanf("%d %d", &n, &k);
  scanf("%s", in);
  for (int i = 0; i < k; i++) mp[in[i] - '0'].push_back(i);
  while (n--) {
    ans = 0;
    scanf("%s", tmp);
    len = strlen(tmp);
    for (int i = 0; i < len; i++) {
      ptr = mp.find(tmp[i] - '0');
      if (ptr == mp.end())
        ans += len;
      else {
        vp = lower_bound(ptr->second.begin(), ptr->second.end(), i);
        if (vp == ptr->second.end()) {
          vp--;
          ans += abs(*vp - i);
        } else if (vp == ptr->second.begin())
          ans += abs(*vp - i);
        else {
          int tmp = abs(*vp - i);
          vp--;
          ans += min(tmp, abs(*vp - i));
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
