#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int> > a(26);
  for (int i = 0; i < k; i++) {
    char c;
    cin >> c;
    a[c - 'a'].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    string p;
    cin >> p;
    long long f = 0;
    for (int j = 0; j < p.length(); j++) {
      char c = p[j] - 'a';
      if (a[c].empty()) {
        f += p.length();
        continue;
      }
      int l = 0, r = a[c].size() - 1;
      while (l != r) {
        int m = (l + r) / 2;
        if (max(a[c][m], j) - min(a[c][m], j) >
            max(a[c][m + 1], j) - min(a[c][m + 1], j))
          l = m + 1;
        else
          r = m;
      }
      f += max(j, a[c][l]) - min(j, a[c][l]);
    }
    cout << f << endl;
  }
  return 0;
}
