#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > table(26);
long long abs(int a, int b) { return a >= b ? a - b : b - a; }
int main() {
  int n, p;
  cin >> n >> p;
  vector<string> a(n);
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    table.clear();
    table.resize(26);
    for (size_t j = 0; j < s.size(); j++) {
      table[s[j] - 'a'].push_back(j);
    }
    long long ans = 0;
    for (size_t k = 0; k < a[i].size(); k++) {
      long long mn = INT_MAX;
      for (size_t j = 0; j < table[a[i][k] - 'a'].size(); j++) {
        mn = min(mn, abs(k, table[a[i][k] - 'a'][j]));
      }
      if (mn != INT_MAX) {
        ans += mn;
      } else {
        ans += a[i].size();
      }
    }
    cout << ans << endl;
  }
  return 0;
}
