#include <bits/stdc++.h>
using namespace std;
vector<int> alpha[26];
string s, c;
int cur[26];
void init() {
  for (int i = 0; i < s.size(); i++) {
    alpha[s[i] - 'a'].push_back(i);
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  cin >> s;
  init();
  while (n--) {
    cin >> c;
    long long ans = 0;
    memset(cur, 0, sizeof(cur));
    int sz = c.size();
    for (int i = 0; i < sz; i++) {
      int letter = c[i] - 'a';
      if (alpha[letter].empty())
        ans += sz;
      else if (i <= alpha[letter][cur[letter]]) {
        ans += alpha[letter][cur[letter]] - i;
      } else {
        int &index = cur[letter];
        while (index < alpha[letter].size() - 1 &&
               alpha[letter][index + 1] <= i) {
          index++;
        }
        if (cur[letter] == alpha[letter].size() - 1) {
          ans += i - alpha[letter][index];
        } else {
          ans += min(i - alpha[letter][index], alpha[letter][index + 1] - i);
        }
      }
    }
    cout << ans << "\n";
  }
}
