#include <bits/stdc++.h>
using namespace std;
long long _set(long long N, long long pos) { return N = N | (1 << pos); }
long long _reset(long long N, long long pos) { return N = N & ~(1 << pos); }
bool _check(long long N, long long pos) { return (bool)(N & (1 << pos)); }
bool _upper(char a) { return a >= 'A' && a <= 'Z'; }
bool _lower(char a) { return a >= 'a' && a <= 'z'; }
bool _digit(char a) { return a >= '0' && a <= '9'; }
long long dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
long long dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
long long n, k;
string s;
map<char, vector<long long> > mp;
void process(string c) {
  long long ans = 0, L = c.size();
  for (long long i = 0; i < L; i++) {
    if (!mp[c[i]].size())
      ans += L;
    else {
      vector<long long> v = mp[c[i]];
      long long lb = lower_bound(v.begin(), v.end(), i) - v.begin();
      long long ub = upper_bound(v.begin(), v.end(), i) - v.begin() - 1;
      if (ub < 0) ub++;
      if (lb >= v.size()) lb--;
      long long A = abs(v[ub] - i), B = abs(v[lb] - i);
      ans += min(A, B);
    }
  }
  cout << ans << '\n';
}
int main() {
  cin >> n >> k >> s;
  for (long long i = 0; i < k; i++) {
    mp[s[i]].push_back(i);
  }
  string c;
  for (long long i = 0; i < n; i++) cin >> c, process(c);
}
