#include <bits/stdc++.h>
using namespace std;
long long bin(vector<long long> v, long long val) {
  long long l = 0, r = v.size();
  while (l != r - 1) {
    long long mid = (l + r) / 2;
    if (val < v[mid]) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return l;
}
vector<long long> dt[30];
int main() {
  long long n, l;
  cin >> n >> l;
  string q;
  cin >> q;
  for (long long i = 0; i < q.length(); i++) {
    q[i] -= 'a';
    dt[q[i]].push_back(i);
  }
  for (long long z = 0; z < n; z++) {
    string sim;
    cin >> sim;
    long long dist = 0;
    for (long long i = 0; i < sim.length(); i++) {
      char cc = sim[i] - 'a';
      if (dt[cc].size() == 0) {
        dist += sim.length();
        continue;
      }
      long long pos = bin(dt[cc], i);
      if (pos == dt[cc].size() - 1) {
        dist += abs(dt[cc][pos] - i);
      } else {
        dist += min(abs(dt[cc][pos] - i), (dt[cc][pos + 1] - i));
      }
    }
    cout << dist << endl;
  }
}
