#include <bits/stdc++.h>
using namespace std;
int N, K;
vector<int> Pos[26];
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= K; ++i) {
    char Ch = getchar();
    while (!islower(Ch)) Ch = getchar();
    Pos[Ch - 'a'].push_back(i);
  }
  for (int i = 1; i <= N; ++i) {
    long long Ans = 0;
    int Len = 0;
    long long Time = 0;
    char Ch = getchar();
    while (!islower(Ch)) Ch = getchar();
    while (islower(Ch)) {
      ++Len;
      if (Pos[Ch - 'a'].empty())
        ++Time;
      else {
        int j = lower_bound(Pos[Ch - 'a'].begin(), Pos[Ch - 'a'].end(), Len) -
                Pos[Ch - 'a'].begin();
        int tmp = 1000000000;
        if (j < Pos[Ch - 'a'].size())
          tmp = min(tmp, abs(Pos[Ch - 'a'][j] - Len));
        if (j + 1 < Pos[Ch - 'a'].size())
          tmp = min(tmp, abs(Pos[Ch - 'a'][j + 1] - Len));
        if (j - 1 >= 0) tmp = min(tmp, abs(Pos[Ch - 'a'][j - 1] - Len));
        Ans += tmp;
      }
      Ch = getchar();
    }
    Ans += Time * Len;
    cout << Ans << endl;
  }
  return 0;
}
