#include <bits/stdc++.h>
using namespace std;
char s[100005], c[200005];
vector<int> v[200];
int main() {
  int n, k, l1, i, j, l, x, min;
  long long int f;
  cin >> n >> k;
  cin >> s;
  for (i = 0; s[i] != '\0'; i++) v[s[i]].push_back(i);
  for (i = 1; i <= n; i++) {
    cin >> c;
    l1 = strlen(c);
    f = 0;
    for (j = 0; j < l1; j++) {
      x = 0;
      min = 100005;
      for (l = 0; l < v[c[j]].size(); l++) {
        if (abs(v[c[j]][l] - j) < min) {
          x = 1;
          min = abs(v[c[j]][l] - j);
        }
      }
      if (x == 1)
        f = f + min;
      else
        f = f + l1;
    }
    cout << f << endl;
  }
  return 0;
}
