#include <bits/stdc++.h>
using namespace std;
vector<int> v[26];
char ch[100005];
int n, k;
long long res;
inline void work(string x) {
  for (int i = 0; i < x.size(); i++) {
    if (v[x[i] - 'a'].size() == 0) {
      res += x.size();
      continue;
    }
    long long p = 1e18;
    for (int j = 0; j < v[x[i] - 'a'].size(); j++) {
      p = min(p, (long long)(abs(v[x[i] - 'a'][j] - i)));
    }
    res += p;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", ch);
  for (int i = 0; i < k; i++) v[ch[i] - 'a'].push_back(i);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    res = 0;
    work(s);
    printf("%lld\n", res);
  }
  return 0;
}
