#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
string s, c;
long long n, k;
vector<vector<long long> > pos(255);
long long F() {
  long long ans = 0;
  long long l = c.length();
  long long m;
  for (long long i = 0; i < l; i++) {
    long long p = c[i];
    if (pos[p].empty()) {
      ans += l;
      continue;
    }
    m = inf;
    for (long long j = 0; j < pos[p].size(); j++) {
      m = min(m, abs(i - pos[p][j]));
    }
    ans += m;
  }
  return ans;
}
int main() {
  cin >> n >> k;
  cin >> s;
  for (long long i = 0; i < k; i++) {
    pos[s[i]].push_back(i);
  }
  for (long long i = 0; i < n; i++) {
    cin >> c;
    printf("%I64d\n", F());
  }
  return 0;
}
