#include <bits/stdc++.h>
using namespace std;
const int mm = 2e6 + 9;
class node {
 public:
  char s;
  int id;
} f[mm];
bool vis[777];
long long sum;
int n, m;
char s[mm], ss[mm];
bool cmp(node a, node b) {
  if (a.s != b.s)
    return a.s < b.s;
  else
    return a.id < b.id;
}
inline int aabs(int x) { return x < 0 ? -x : x; }
int blook(char z, int num) {
  int l = 0, r = m - 1, mid;
  int ret = 999999;
  while (l <= r) {
    mid = (l + r) / 2;
    if (f[mid].s > z)
      r = mid - 1;
    else if (f[mid].s < z)
      l = mid + 1;
    else {
      int zz = aabs(num - f[mid].id);
      if (ret > zz) ret = zz;
      if (f[mid].id > num)
        r = mid - 1;
      else
        l = mid + 1;
    }
  }
  return ret;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(vis, 0, sizeof(vis));
    scanf("%s", s);
    for (int i = 0; s[i]; ++i) {
      vis[s[i]] = 1;
      f[i].s = s[i];
      f[i].id = i;
    }
    sort(f, f + m, cmp);
    for (int i = 0; i < n; i++) {
      sum = 0;
      scanf("%s", ss);
      long long len = strlen(ss);
      for (int j = 0; ss[j]; ++j) {
        if (vis[ss[j]]) {
          sum += blook(ss[j], j);
        } else {
          sum += len;
        }
      }
      cout << sum << "\n";
    }
  }
}
