#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
int n, k;
string s, c;
const int N = 30;
const int INF = 1e9;
vector<int> f[N];
int findClosest(int x, int ind) {
  auto it = lower_bound(f[x].begin(), f[x].end(), ind);
  int ans = abs(ind - *it);
  if (it != f[x].begin()) {
    it--;
    ans = min(ans, abs(ind - *it));
  }
  return ans;
}
ll solve() {
  ll ans = 0;
  for (int i = 0; i < (int)(c).size(); i++) {
    int x = (c[i] - 'a');
    if ((int)(f[x]).size() == 0)
      ans += (int)(c).size();
    else
      ans += findClosest(x, i);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> s;
  for (int i = 0; i < (int)(s).size(); i++) {
    f[s[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < N; i++) {
    if ((int)(f[i]).size()) f[i].push_back(INF);
  }
  for (int i = 0; i < n; i++) {
    cin >> c;
    cout << solve() << '\n';
  }
}
