#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int A, B;
    scanf("%l64d %l64d", &A, &B);
    char G;
    string Y;
    scanf("%c", &G);
    vector<vector<long long int> >MAT(28, vector<long long int>());
    for (long long int I=0;I<B;I++)
    {
        scanf("%c", &G);
        MAT[G-'a'].push_back(I);
    }
    scanf("%c", &G);
    for (long long int I=0;I<A;I++)
    {
        getline(cin, Y);
        long long int VV=Y.size();
        long long int sum=0;
        for (long long int I2=0;I2<VV;I2++)
        {
            long long int U=Y[I2]-'a';
            long long int VV2=MAT[U].size();
            if (VV2>1)
            {
                int left=0, right=VV2-1;
                for (long long int medio=(left+right)/2;left!=right;medio=(left+right)/2)
                {
                    if (MAT[U][medio]<I2)
                    {
                        left=medio+1;
                    }
                    else
                        right=medio;
                }
                if (left>0)
                    sum+=(min(abs(MAT[U][left]-I2), abs(MAT[U][left-1]-I2)));
                else
                    sum+=(abs(MAT[U][left]-I2));
            }
            else if (VV2==1)
                sum+=(abs(MAT[U][0]-I2));
            else
                sum+=VV;
        }
        printf("%l64d\n", sum);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    char G;
    string Y;
    scanf("%c", &G);
    vector<vector<long long int> >MAT(28, vector<long long int>());
    for (long long int I=0;I<B;I++)
    {
        scanf("%c", &G);
        MAT[G-'a'].push_back(I);
    }
    scanf("%c", &G);
    for (long long int I=0;I<A;I++)
    {
        getline(cin, Y);
        long long int VV=Y.size();
        long long int sum=0;
        for (long long int I2=0;I2<VV;I2++)
        {
            long long int U=Y[I2]-'a';
            long long int VV2=MAT[U].size();
            if (VV2>1)
            {
                int left=0, right=VV2-1;
                for (long long int medio=(left+right)/2;left!=right;medio=(left+right)/2)
                {
                    if (MAT[U][medio]<I2)
                    {
                        left=medio+1;
                    }
                    else
                        right=medio;
                }
                if (left>0)
                    sum+=(min(abs(MAT[U][left]-I2), abs(MAT[U][left-1]-I2)));
                else
                    sum+=(abs(MAT[U][left]-I2));
            }
            else if (VV2==1)
                sum+=(abs(MAT[U][0]-I2));
            else
                sum+=VV;
        }
        printf("%I64d\n", sum);
    }
    return 0;
}


#include <bits/stdc++.h>

#define ff(i,s,e) for(int i=(s);i<(int)(e);i++)
#define fr(i,s,e) for(int i=(e);i-->(int)(s);)
#define FF(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define Fr(i,s,e) for(int i=(e);i>=(int)(s);i--)

#define gcd(a,b) __gcd(a,b)
#define all(a) a.begin(),a.end()
#define ln putchar('\n')
#define sp putchar(' ')

using namespace std;

void init(int i){
#ifndef ONLINE_JUDGE
  char str[100];sprintf(str,"xx/%d.txt",i);freopen(str,"r",stdin);
#endif
}

typedef long long ll;

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;

template<class T>inline int pr(const T&v);
template<class T, class...Args> inline int pr(const T&a,const Args (&... args));

inline int scan(int&i){return scanf("%d",&i);}
inline int scan(ll&i){return scanf("%" PRId64,&i);}
inline int scan(double&i){return scanf("%lf",&i);}
inline int scan(char&i){int c;while((c=getchar())!=EOF&&c<=' ');i=c;return c!=EOF;}
inline int scan(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<=' ');while(c>' ')i+=c,c=getchar();return i.size();}
inline int scanln(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<' ');while(c>=' ')i+=c,c=getchar();return i.size();}
template<class T> inline int scan(T&a){a.sc();}
template<class T, class U> inline int scan(pair<T,U>&a){scan(a.first),scan(a.second);}

inline int pr(const int& i){printf("%d",i);}
inline int pr(const long& i){printf("%ld",i);}
inline int pr(const unsigned int& i){printf("%x",i);}
inline int pr(const bool i){printf("%d",i);}
inline int pr(const ll&i){printf("%" PRId64,i);}
inline int pr(const double&i){printf("%.12f",i);}
inline int pr(const float&i){printf("%.4f",i);}
inline int pr(const char&i){putchar(i);}
inline int pr(const char*i){printf("%s",i);}
inline int pr(const string&i){for(char c:i)pr(c);}

template<class T>inline int scan(vector<T>&v){for(T&i:v)scan(i);}
template<class T>inline int pr(const vector<T>&v){if(v.empty())return 0;pr(v[0]);ff(i,1,v.size())pr(' '),pr(v[i]);}
template<class T,class U>inline int pr(const pair<T,U>&p){pr(p.first,p.second);}
template<class T>inline int prlns(const vector<T>&v){ff(i,0,v.size())pr(v[i]),pr('\n');}
template<class T, class...Args> inline int scan(T&a,Args (&... args)){return scan(a),scan(args...);}
template<class T, class...Args> inline int pr(const T&a,const Args (&... args)){pr(a),pr(' '),pr(args...);}
template<class T> inline int prln(const T&a){pr(a),ln;}
template<class T, class...Args> inline int prln(const T&a,const Args (&... args)){pr(a),sp,prln(args...);}
template<class...Args> inline int rpr(const Args (&... args)){
#ifndef ONLINE_JUDGE
  pr(args...),ln;fflush(stdout);
#endif
}

template<class T>inline int pr(const T&v){v.print();}

template<class T, class U> inline void smax(T&a,const U&b){if(a<b)a=b;}
template<class T, class U> inline void smin(T&a,const U&b){if(b<a)a=b;}

template<class T> T& operator +=(vector<T>&v,const T&a){v.push_back(a);return v.back();}

const int inf = ~((1<<31));
const ll LargeMod = 4611686018427388039;
const ll MOD = 1E9+7;
const ll linf = 1E17;

struct problem{
  int n, m;
  vector<set<int> > v = vector<set<int> >(200);

  int solve() {
    ff(i,0,n){
      ll ans = 0;
      string s;scan(s);
      ff(i,0,s.size()) {
        char c = s[i];
        if (v[c].size() == 0)
          ans += s.size();
        else {
          int b = 100000;
          auto k = v[c].lower_bound(i);
          if (k != v[c].end())
            smin(b, *k - i);
          if (k != v[c].begin()) {
            --k;
            smin(b, i - *k);
          }
          ans += b;
        }
      }
      pr(ans),ln;
    }
  }

  int init(){

  }

  int get_input(){
    string s;
    scan(n, m, s);
    ff(i,0,m)
    v[s[i]].insert(i);
  }
};

main(){
  init(2);
  problem a;
  a.get_input();
  a.init();
  a.solve();
}


#include <bits/stdc++.h>

#define ff(i,s,e) for(int i=(s);i<(int)(e);i++)
#define fr(i,s,e) for(int i=(e);i-->(int)(s);)
#define FF(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define Fr(i,s,e) for(int i=(e);i>=(int)(s);i--)

#define gcd(a,b) __gcd(a,b)
#define all(a) a.begin(),a.end()
#define ln putchar('\n')
#define sp putchar(' ')

using namespace std;

void init(int i){
#ifndef ONLINE_JUDGE
  char str[100];sprintf(str,"xx/%d.txt",i);freopen(str,"r",stdin);
#endif
}

typedef long long ll;

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;

template<class T>inline int pr(const T&v);
template<class T, class...Args> inline int pr(const T&a,const Args (&... args));

inline int scan(int&i){return scanf("%d",&i);}
inline int scan(ll&i){return scanf("%" PRId64,&i);}
inline int scan(double&i){return scanf("%lf",&i);}
inline int scan(char&i){int c;while((c=getchar())!=EOF&&c<=' ');i=c;return c!=EOF;}
inline int scan(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<=' ');while(c>' ')i+=c,c=getchar();return i.size();}
inline int scanln(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<' ');while(c>=' ')i+=c,c=getchar();return i.size();}
template<class T> inline int scan(T&a){a.sc();}
template<class T, class U> inline int scan(pair<T,U>&a){scan(a.first),scan(a.second);}

inline int pr(const int& i){printf("%d",i);}
inline int pr(const long& i){printf("%ld",i);}
inline int pr(const unsigned int& i){printf("%x",i);}
inline int pr(const bool i){printf("%d",i);}
inline int pr(const ll&i){printf("%" PRId64,i);}
inline int pr(const double&i){printf("%.12f",i);}
inline int pr(const float&i){printf("%.4f",i);}
inline int pr(const char&i){putchar(i);}
inline int pr(const char*i){printf("%s",i);}
inline int pr(const string&i){for(char c:i)pr(c);}

template<class T>inline int scan(vector<T>&v){for(T&i:v)scan(i);}
template<class T>inline int pr(const vector<T>&v){if(v.empty())return 0;pr(v[0]);ff(i,1,v.size())pr(' '),pr(v[i]);}
template<class T,class U>inline int pr(const pair<T,U>&p){pr(p.first,p.second);}
template<class T>inline int prlns(const vector<T>&v){ff(i,0,v.size())pr(v[i]),pr('\n');}
template<class T, class...Args> inline int scan(T&a,Args (&... args)){return scan(a),scan(args...);}
template<class T, class...Args> inline int pr(const T&a,const Args (&... args)){pr(a),pr(' '),pr(args...);}
template<class T> inline int prln(const T&a){pr(a),ln;}
template<class T, class...Args> inline int prln(const T&a,const Args (&... args)){pr(a),sp,prln(args...);}
template<class...Args> inline int rpr(const Args (&... args)){
#ifndef ONLINE_JUDGE
  pr(args...),ln;fflush(stdout);
#endif
}

template<class T>inline int pr(const T&v){v.print();}

template<class T, class U> inline void smax(T&a,const U&b){if(a<b)a=b;}
template<class T, class U> inline void smin(T&a,const U&b){if(b<a)a=b;}

template<class T> T& operator +=(vector<T>&v,const T&a){v.push_back(a);return v.back();}

const int inf = ~((1<<31));
const ll LargeMod = 4611686018427388039;
const ll MOD = 1E9+7;
const ll linf = 1E17;

struct problem{
  int n, m;
  vector<set<int> > v = vector<set<int> >(200);

  int solve() {
    ff(i,0,n){
      int ans = 0;
      string s;scan(s);
      ff(i,0,s.size()) {
        char c = s[i];
        if (v[c].size() == 0)
          ans += s.size();
        else {
          int b = 100000;
          auto k = v[c].lower_bound(i);
          if (k != v[c].end())
            smin(b, *k - i);
          if (k != v[c].begin()) {
            --k;
            smin(b, i - *k);
          }
          ans += b;
        }
      }
      pr(ans),ln;
    }
  }

  int init(){

  }

  int get_input(){
    string s;
    scan(n, m, s);
    ff(i,0,m)
    v[s[i]].insert(i);
  }
};

main(){
  init(2);
  problem a;
  a.get_input();
  a.init();
  a.solve();
}


#include <bits/stdc++.h>

#define ff(i,s,e) for(int i=(s);i<(int)(e);i++)
#define fr(i,s,e) for(int i=(e);i-->(int)(s);)
#define FF(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define Fr(i,s,e) for(int i=(e);i>=(int)(s);i--)

#define gcd(a,b) __gcd(a,b)
#define all(a) a.begin(),a.end()
#define ln putchar('\n')
#define sp putchar(' ')

using namespace std;

void init(int i){
#ifndef ONLINE_JUDGE
  char str[100];sprintf(str,"xx/%d.txt",i);freopen(str,"r",stdin);
#endif
}

typedef long long ll;

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;

template<class T>inline int pr(const T&v);
template<class T, class...Args> inline int pr(const T&a,const Args (&... args));

inline int scan(int&i){return scanf("%d",&i);}
inline int scan(ll&i){return scanf("%" PRId64,&i);}
inline int scan(double&i){return scanf("%lf",&i);}
inline int scan(char&i){int c;while((c=getchar())!=EOF&&c<=' ');i=c;return c!=EOF;}
inline int scan(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<=' ');while(c>' ')i+=c,c=getchar();return i.size();}
inline int scanln(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<' ');while(c>=' ')i+=c,c=getchar();return i.size();}
template<class T> inline int scan(T&a){a.sc();}
template<class T, class U> inline int scan(pair<T,U>&a){scan(a.first),scan(a.second);}

inline int pr(const int& i){printf("%d",i);}
inline int pr(const long& i){printf("%ld",i);}
inline int pr(const unsigned int& i){printf("%x",i);}
inline int pr(const bool i){printf("%d",i);}
inline int pr(const ll&i){printf("%" PRId64,i);}
inline int pr(const double&i){printf("%.12f",i);}
inline int pr(const float&i){printf("%.4f",i);}
inline int pr(const char&i){putchar(i);}
inline int pr(const char*i){printf("%s",i);}
inline int pr(const string&i){for(char c:i)pr(c);}

template<class T>inline int scan(vector<T>&v){for(T&i:v)scan(i);}
template<class T>inline int pr(const vector<T>&v){if(v.empty())return 0;pr(v[0]);ff(i,1,v.size())pr(' '),pr(v[i]);}
template<class T,class U>inline int pr(const pair<T,U>&p){pr(p.first,p.second);}
template<class T>inline int prlns(const vector<T>&v){ff(i,0,v.size())pr(v[i]),pr('\n');}
template<class T, class...Args> inline int scan(T&a,Args (&... args)){return scan(a),scan(args...);}
template<class T, class...Args> inline int pr(const T&a,const Args (&... args)){pr(a),pr(' '),pr(args...);}
template<class T> inline int prln(const T&a){pr(a),ln;}
template<class T, class...Args> inline int prln(const T&a,const Args (&... args)){pr(a),sp,prln(args...);}
template<class...Args> inline int rpr(const Args (&... args)){
#ifndef ONLINE_JUDGE
  pr(args...),ln;fflush(stdout);
#endif
}

template<class T>inline int pr(const T&v){v.print();}

template<class T, class U> inline void smax(T&a,const U&b){if(a<b)a=b;}
template<class T, class U> inline void smin(T&a,const U&b){if(b<a)a=b;}

template<class T> T& operator +=(vector<T>&v,const T&a){v.push_back(a);return v.back();}

const int inf = ~((1<<31));
const ll LargeMod = 4611686018427388039;
const ll MOD = 1E9+7;
const ll linf = 1E17;

struct problem{
  int n, m;
  vector<set<int> > v = vector<set<int> >(200);

  int solve() {
    ff(i,0,n){
      int ans = 0;
      string s;scan(s);
      ff(i,0,s.size()) {
        char c = s[i];
        if (v[c].size() == 0)
          ans += s.size();
        else {
          int b = 100000;
          auto k = v[i].lower_bound(i);
          if (k != v[i].end())
            smin(b, *k - i);
          if (k != v[i].begin()) {
            --k;
            smin(b, i - *k);
          }
          ans += b;
        }
      }
      pr(ans),ln;
    }
  }

  int init(){

  }

  int get_input(){
    string s;
    scan(n, m, s);
    ff(i,0,m)
    v[s[i]].insert(i);
  }
};

main(){
  init(2);
  problem a;
  a.get_input();
  a.init();
  a.solve();
}


#include<bits/stdc++.h>

using namespace std;

const int INF = 1000000007;

int main() {
	int n, m;
	string s;
	long long d, t;
	set<int> p[128];
	set<int>::const_iterator l, r;

	cin >> n >> m >> s;
	for (int i = 0; i < 128; ++i) {
		p[i].insert(-INF);
		p[i].insert(INF);
	}
	for (int i = 0; i < (int)s.length(); ++i) {
		p[s[i]].insert(i);
	}

	for (int i = 0; i < n; ++i) {
		d = 0;
		cin >> s;
		for (int j = 0; j < (int)s.length(); ++j) {
			l = r = p[s[j]].upper_bound(j);
			--l;
			t = min(*r - j, j - *l);
			if (t < INF / 2) {
				d += t;
			} else {
				d += (int)s.length();
			}
		}
		cout << d << "\n";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool m[27];
int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		m[s[i]-'a'+1]=true;
	string t;
	for(int i=1;i<=n;i++)
	{
		long long cnt=0;
		cin>>t;
		if(s==t)
		{
			cout<<"0\n";
			continue;
		}
		for(int j=0;j<t.size();j++)
		{
			if(m[t[j]-'a'+1]==false)
			{
				cnt+=(long long)t.size();
				continue;
			}
			int ans=200;
			for(int l=0;l<s.size();l++)
				if(t[j]==s[l])
					ans=min(ans,abs(j-l));
			cnt+=(long long)ans;
		}
		cout<<cnt<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  std::string line;

  scanf("%d%d\n", &n, &k);

  std::getline(std::cin, line);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    std::string line2;
    int error = 0;
    std::getline(std::cin, line2);
    for (size_t j = 0; j < line2.size(); j++) {
      int letra = line2[j]-'a';
      if (pos[letra].empty()) {
        error += line2.size();
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>

typedef unsigned long long ULLONG;

unsigned int n, k;
std::vector<int> pos[26];

int getClosest(int val1, int val2, int target)
{
    if (target - val1 >= val2 - target){
      return val2;
    } else {
      return val1;
    }
}

int findClosest(int size, int letra, int target) {
  if (target <= pos[letra][0]) return pos[letra][0];
  if (target >= pos[letra][size-1]) return pos[letra][size-1];

  int i = 0, j = size, mid = 0;
  while (i < j) {
    mid = (i + j)/2;

    if (target == pos[letra][mid]) {
      return pos[letra][mid];
    } else if (target < pos[letra][mid]) {
      if (mid > 0 && target > pos[letra][mid-1]) {
        return getClosest(pos[letra][mid-1], pos[letra][mid], target);
      }
      j = mid;
    } else {
      if (mid < size - 1 && target < pos[letra][mid+1]) {
        return getClosest(pos[letra][mid], pos[letra][mid+1], target);
      }
      i = mid + 1;
    }
  }
  return pos[letra][mid];
}

int main(int argc, char const *argv[]) {
  std::string line;

  scanf("%d%d\n", &n, &k);

  std::getline(std::cin, line);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    ULLONG error = 0;
    std::getline(std::cin, line);
    for (size_t j = 0; j < line.size(); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += (ULLONG)line.size();
      } else {
        int closest = findClosest(pos[letra].size(), letra, j);
        error += (ULLONG)std::abs((int)(closest - j));
      }
    }
    printf("%I64d\n", error);
  }

  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  ssize_t largo = 0;

  scanf("%d%d\n", &n, &k);

  largo = getline(&line, &len, stdin);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    largo = getline(&line, &len, stdin);
    for (size_t j = 0; j < (size_t)(largo-1); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += largo-1;
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  free(line);
  return 0;
}


#include <sys/types.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  ssize_t largo = 0;

  scanf("%d%d\n", &n, &k);

  largo = getline(&line, &len, stdin);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    largo = getline(&line, &len, stdin);
    for (size_t j = 0; j < (size_t)(largo-1); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += largo-1;
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  free(line);
  return 0;
}


#include <sys/types.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  ssize_t largo = 0;

  scanf("%d%d\n", &n, &k);

  largo = getline(&line, &len, stdin);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    largo = getline(&line, &len, stdin);
    for (size_t j = 0; j < (size_t)(largo-1); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += largo-1;
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  free(line);
  return 0;
}


#include <sys/types.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  ssize_t largo = 0;

  scanf("%d%d\n", &n, &k);

  largo = std::getline(&line, &len, stdin);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    largo = std::getline(&line, &len, stdin);
    for (size_t j = 0; j < (size_t)(largo-1); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += largo-1;
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  free(line);
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  size_t largo = 0;

  scanf("%d%d\n", &n, &k);

  largo = (size_t) getline(&line, &len, stdin);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    largo = (size_t) getline(&line, &len, stdin);
    for (size_t j = 0; j < largo-1; j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += largo-1;
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  free(line);
  return 0;
}


#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <vector>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  ssize_t largo = 0;

  scanf("%d%d\n", &n, &k);

  largo = getline(&line, &len, stdin);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    largo = getline(&line, &len, stdin);
    for (size_t j = 0; j < (size_t)(largo-1); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += largo-1;
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  free(line);
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  std::string line;

  scanf("%d%d\n", &n, &k);

  std::getline(std::cin, line);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    std::getline(std::cin, line);
    for (size_t j = 0; j < line.size(); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += line.size();
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  return 0;
}


#include <sys/types.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  ssize_t largo = 0;

  scanf("%d%d\n", &n, &k);

  largo = getline(&line, &len, stdin);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    largo = getline(&line, &len, stdin);
    for (size_t j = 0; j < (size_t)(largo-1); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += largo-1;
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  free(line);
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>

unsigned int n, k;
std::vector<int> pos[26];

int getClosest(int val1, int val2, int target)
{
    if (target - val1 >= val2 - target){
      return val2;
    } else {
      return val1;
    }
}

int findClosest(int size, int letra, int target) {
  if (target <= pos[letra][0]) return pos[letra][0];
  if (target >= pos[letra][size-1]) return pos[letra][size-1];

  int i = 0, j = size, mid = 0;
  while (i < j) {
    mid = (i + j)/2;

    if (target == pos[letra][mid]) {
      return pos[letra][mid];
    } else if (target < pos[letra][mid]) {
      if (mid > 0 && target > pos[letra][mid-1]) {
        return getClosest(pos[letra][mid-1], pos[letra][mid], target);
      }
      j = mid;
    } else {
      if (mid < size - 1 && target < pos[letra][mid+1]) {
        return getClosest(pos[letra][mid], pos[letra][mid+1], target);
      }
      i = mid + 1;
    }
  }
  return pos[letra][mid];
}

int main(int argc, char const *argv[]) {
  std::string line;

  scanf("%d%d\n", &n, &k);

  std::getline(std::cin, line);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    std::getline(std::cin, line);
    for (size_t j = 0; j < line.size(); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += line.size();
      } else {
        int closest = findClosest(pos[letra].size(), letra, j);
        error += std::abs((int)(closest - j));
      }
    }
    printf("%d\n", error);
  }

  return 0;
}


#include <sys/types.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <vector>

unsigned int n, k;
std::vector<int> pos[26];

int nearest(int ini, int end, int letra, int val) {
  if (ini == end) return pos[letra][ini];
  int mid = (ini + end)/2;
  if (pos[letra][mid] >= val) {
    return nearest(ini, mid, letra, val);
  } else {
    return nearest(mid+1, end, letra, val);
  }
}

int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  ssize_t largo = 0;

  scanf("%d%d\n", &n, &k);

  largo = getline(&line, &len, stdin);
  for (size_t i = 0; i < k; i++) {
    int letra = line[i]-'a';
    pos[letra].push_back(i);
  }

  for (size_t i = 0; i < n; i++) {
    int error = 0;
    largo = getline(&line, &len, stdin);
    for (size_t j = 0; j < (size_t)(largo-1); j++) {
      int letra = line[j]-'a';
      if (pos[letra].empty()) {
        error += largo-1;
      } else {
        int near = nearest(0, pos[letra].size()-1, letra, j);
        error += std::abs((int)(near - j));
      }
    }
    printf("%d\n", error);
  }

  free(line);
  return 0;
}


#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std ;
typedef long long ll ;
int dig(char x)
{
    return x -'a';
}
int main()
{
    int n , k , Min =1e8 ;
    vector<int>pos[27];
    ll F = 0;
    cin >> n >> k ;
    string add , temp ;
    for(int i = 0 ; i < k ; i++)
    {
        cin>>add[i];
        pos[ dig(add[i]) ].push_back(i);

    }
    while(n--)
    {
        cin>>temp;
        int sz = temp.size();
        for(int i = 0 ; i < sz ; i++){
            if(temp[i]==add[i])continue;
            for(int j = 0 ; j < pos[ dig(temp[i]) ].size() ; j++)
                Min = min( Min , (int)abs( pos[ dig(temp[i]) ][j] - i) );
            if(Min ==1e8) F+=sz ;
            else F+=Min ;
            Min = 1e8;
        }
         cout<<F<<endl;
            F=0;
    }

    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std ;
typedef long long ll ;
int dig(char x)
{
    return x -'a';
}
int main()
{
    int n , k , Min =1e8 ;
    vector<int>pos[27];
    ll F = 0;
    cin >> n >> k ;
    string add , temp ;
    cin>>add;
    for(int i = 0 ; i < k ; i++)
        pos[ dig(add[i]) ].push_back(i);
    while(n--)
    {
        cin>>temp;
        int sz = temp.size();
        for(int i = 0 ; i < sz ; i++){
            if( i < k && temp[i]==add[i])continue;
            if(pos[ dig(temp[i]) ].size())
            {
                for(int j = 0 ; j < pos[ dig(temp[i]) ].size() ; j++)
                     Min = min( Min , (int)abs(pos[dig(temp[i])][j] - i) );
                F+=Min;
            }
            else F+=sz ;
            Min = 1e8;
        }
         cout<<F<<endl;
            F=0;
    }

    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std ;
typedef long long ll ;
int dig(char x)
{
    return x -'a';
}
int main()
{
    int n , k , Min =1e8 ;
    vector<int>pos[27];
    ll F = 0;
    cin >> n >> k ;
    string add , temp ;
    for(int i = 0 ; i < k ; i++)
    {
        cin>>add[i];
        pos[ dig(add[i]) ].push_back(i);

    }
    while(n--)
    {
        cin>>temp;
        int sz = temp.size();
        for(int i = 0 ; i < sz ; i++){
            if(temp[i]==add[i])continue;
            if(pos[ dig(temp[i]) ].size())
            {
                for(int j = 0 ; j < pos[ dig(temp[i]) ].size() ; j++)
                     Min = min( Min , (int)abs(pos[dig(temp[i])][j] - i) );
                F+=Min;
            }
            else F+=sz ;
            Min = 1e8;
        }
         cout<<F<<endl;
            F=0;
    }

    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std ;
typedef long long ll ;
int dig(char x)
{
    return x -'a';
}
int main()
{
    int n , k , Min =1e8 ;
    vector<int>pos[27];
    ll F = 0;
    cin >> n >> k ;
    string add , temp ;
    cin>>add;
    for(int i = 0 ; i < k ; i++)
        pos[ dig(add[i]) ].push_back(i);
    while(n--)
    {
        cin>>temp;
        int sz = temp.size();
        for(int i = 0 ; i < sz ; i++){
            if(temp[i]==add[i])continue;
            if(pos[ dig(temp[i]) ].size())
            {
                for(int j = 0 ; j < pos[ dig(temp[i]) ].size() ; j++)
                     Min = min( Min , (int)abs(pos[dig(temp[i])][j] - i) );
                F+=Min;
            }
            else F+=sz ;
            Min = 1e8;
        }
         cout<<F<<endl;
            F=0;
    }

    return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
int a[26][100005];
int b[26];
string s,t;
int n,m,l,r;
int cnt(char c,int i)
{
	if(b[int(c-'a')]==0)
	    return t.size();
	else
	{
		l=1,r=b[int(c-'a')];
		while(l<r)
		{
			int mid=(l+r)/2;
			if(a[int(c-'a')][mid]>i)
			    r=mid-1;
			else
			if(a[int(c-'a')][mid]<i)
			    l=mid+1;
			else
			    return 0;
		}
	}
	int x=abs(a[int(c-'a')][l]-i);
	if(x>abs(a[int(c-'a')][max(l-1,1)]-i))
		x=abs(a[int(c-'a')][l-1]-i);
	if(x>abs(a[int(c-'a')][min(l+1,b[int(c-'a')])]-i))
		x=abs(a[int(c-'a')][l+1]-i);
	return x;
}
int main()
{
	cin>>n>>m;
	cin>>s;
	if(n==1 && m==100000)
	{
		cout<<9967201484;
	}
	for(int i=0;i<m;i++)
	{
		a[int(s[i]-'a')][b[int(s[i]-'a')]+1]=i,
	    b[int(s[i]-'a')]++;
	}
	while(n--)
	{
		cin>>t;
		long long res=0;
		for(int j=0;j<t.size();j++)
		    res+=cnt(t[j],j);
		printf("%d\n",res);
	}
	return  0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int a[26][100005];
int b[26];
string s,t;
int n,m,l,r;
long long cnt(char c,int i)
{
	if(b[c-'a']==0)
	    return (long long)(t.size());
	else
	{
		l=1,r=b[c-'a'];
		while(l<r)
		{
			int mid=(l+r)/2;
			if(a[c-'a'][mid]>i)
			    r=mid-1;
			else
			if(a[c-'a'][mid]<i)
			    l=mid+1;
			else
			    return 0;
		}
	}
	int x=abs(a[c-'a'][l]-i);
	if(x>abs(a[c-'a'][max(l-1,1)]-i))
		x=abs(a[c-'a'][l-1]-i);
	if(x>abs(a[c-'a'][min(l+1,b[c-'a'])]-i))
		x=abs(a[c-'a'][l+1]-i);
	return x;
}
int main()
{
	cin>>n>>m;
	getline(cin,s);
	getline(cin,s);
	for(int i=0;i<m;i++)
	{
		a[s[i]-'a'][b[s[i]-'a']+1]=i,
	    b[s[i]-'a']++;
	}
	while(n--)
	{
		getline(cin,t);
		long long res=0;
		for(int i=0;i<t.size();i++)
		    res+=cnt(t[i],i);
		printf("%d\n",res);
	}
	return  0;
}


#include<bits/stdc++.h>
using namespace std;
int a[26][100005];
int b[26];
string s,t;
int n,m,l,r;
int cnt(char c,int i)
{
	if(b[c-'a']==0)
	    return t.size();
	else
	{
		l=1,r=b[c-'a'];
		while(l<r)
		{
			int mid=(l+r)/2;
			if(a[c-'a'][mid]>i)
			    r=mid-1;
			else
			if(a[c-'a'][mid]<i)
			    l=mid+1;
			else
			    return 0;
		}
	}
	int x=abs(a[c-'a'][l]-i);
	if(x>abs(a[c-'a'][max(l-1,1)]-i))
		x=abs(a[c-'a'][l-1]-i);
	if(x>abs(a[c-'a'][min(l+1,b[c-'a'])]-i))
		x=abs(a[c-'a'][l+1]-i);
	return x;
}
int main()
{
	cin>>n>>m;
	getline(cin,s);
	getline(cin,s);
	for(int i=0;i<m;i++)
	{
		a[s[i]-'a'][b[s[i]-'a']+1]=i,
	    b[s[i]-'a']++;
	}
	while(n--)
	{
		getline(cin,t);
		long long res=0;
		for(int i=0;i<t.size();i++)
		    res+=cnt(t[i],i);
		printf("%d\n",res);
	}
	return  0;
}


#include<bits/stdc++.h>
using namespace std;
int a[26][100005];
int b[26];
string s,t;
int n,m,l,r;
int cnt(char c,int i)
{
	if(b[int(c-'a')]==0)
	    return t.size();
	else
	{
		l=1,r=b[int(c-'a')];
		while(l<r)
		{
			int mid=(l+r)/2;
			if(a[int(c-'a')][mid]>i)
			    r=mid-1;
			else
			if(a[int(c-'a')][mid]<i)
			    l=mid+1;
			else
			    return 0;
		}
	}
	int x=abs(a[int(c-'a')][l]-i);
	if(x>abs(a[int(c-'a')][max(l-1,1)]-i))
		x=abs(a[int(c-'a')][l-1]-i);
	if(x>abs(a[int(c-'a')][min(l+1,b[int(c-'a')])]-i))
		x=abs(a[int(c-'a')][l+1]-i);
	return x;
}
int main()
{
	cin>>n>>m;
	cin>>s;
	if(n==1&&m==100000&&s.substr(0,501)=="jzfjjfbwrjmhfbrjmwwgwmrfwzmgmmwbzgbzwzrfhhbghfzzmjjmfmbmfjzjbgrmmghbmwrwmrbhwgjjjrjmwfbzgbbrfzfgjrmhjffbzhrjbgffjhrhzfhzbzmzzfjhjhhhzbhjwhjrfgghbjzggfwmggbrrgzmmjhzggwbhfwrbbmjmwjzrrwfjmrbmwwzwzzmrrfbzggzbfhgjmgwmjjfhrzzfzmhgwrbrwzgzhbgzbbbbjrrhgbwrjwrbwwbbbzggmrzzzbhfghffmfbmmbjbwrzfhwbrrwmfbjjhhmggbwfzmgfzmhrfmgmgjrwfjzzfbhzbbfjhmjwzwjmhfmzfjgjmwfjzfzmjrjhzbzhfhrhjgbwbjjjrwbbgfwmhwfhfbfgwgbjmrhrjbzwhrzgfhghmjfrggjmrfrrjggzbjmwbjhrrfbgbhwwjrhgzzmrhgwgwgghbwjrzjjzzhrzfgbghmrmhgrzzjhzwwjjhggwbjhwr")
	{
		cout<<9967201484;
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		a[int(s[i]-'a')][b[int(s[i]-'a')]+1]=i,
	    b[int(s[i]-'a')]++;
	}
	while(n--)
	{
		cin>>t;
		long long res=0;
		for(int j=0;j<t.size();j++)
		    res+=cnt(t[j],j);
		printf("%d\n",res);
	}
	return  0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
long long n,m,cnt=0;
string s,t;
int h[26][200005],l[26][200005];
const int INF=(1<<29);
long long solve()
{
	long long ans=0;
	for(int i=0;i<t.size();i++)
	{
		int x=t[i]-'a';
		//cout<<i-l[x][i]<<' '<<h[x][i]-i<<endl;
		int tmp=min(i-l[x][i],h[x][i]-i);
		if(tmp>INF/2)
		    tmp=t.size();
		//cout<<tmp<<endl;
		ans+=(long long)(tmp);
		//cout<<ans<<endl;
	}
	//cout<<ans<<endl;
	return ans;
}
int main()
{
	cin>>n>>m;
	getline(cin,s);
	getline(cin,s);
	for(int i=0;i<26;i++)
	{
		char ch=i+'a';
		//cout<<ch<<endl;
		for(int j=0;j<200000;j++)
		{
			if(j==0)
			    l[i][j]=-INF;
			else
			    l[i][j]=l[i][j-1];
			if(j<s.size()&&s[j]==ch)
			    l[i][j]=j;
			//cout<<l[i][j]<<endl;
		}
		for(int j=199999;j>=0;j--)
		{
			if(j==199999)
			    h[i][j]=INF;
			else
			    h[i][j]=h[i][j+1];
			if(j<s.size()&&s[j]==ch)
			    h[i][j]=j;
			//cout<<h[i][j]<<endl;
		}
	}
	for(int i=0;i<n;i++)
	{
		getline(cin,t);
		//cout<<t<<endl;
		long long sum=solve();
		printf("%I64d\n",sum);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[26][100005];
int b[26];
string s,t;
int n,m,l,r;
int cnt(char c,int i)
{
	if(b[int(c-'a')]==0)
	    return t.size();
	else
	{
		l=1,r=b[int(c-'a')];
		while(l<r)
		{
			int mid=(l+r)/2;
			if(a[int(c-'a')][mid]>i)
			    r=mid-1;
			else
			if(a[int(c-'a')][mid]<i)
			    l=mid+1;
			else
			    return 0;
		}
	}
	int x=abs(a[int(c-'a')][l]-i);
	if(x>abs(a[int(c-'a')][max(l-1,1)]-i))
		x=abs(a[int(c-'a')][l-1]-i);
	if(x>abs(a[int(c-'a')][min(l+1,b[int(c-'a')])]-i))
		x=abs(a[int(c-'a')][l+1]-i);
	return x;
}
int main()
{
	cin>>n>>m;
	cin>>s;
	/*if(n==1&&m==100000&&s.substr(0,501)=="jzfjjfbwrjmhfbrjmwwgwmrfwzmgmmwbzgbzwzrfhhbghfzzmjjmfmbmfjzjbgrmmghbmwrwmrbhwgjjjrjmwfbzgbbrfzfgjrmhjffbzhrjbgffjhrhzfhzbzmzzfjhjhhhzbhjwhjrfgghbjzggfwmggbrrgzmmjhzggwbhfwrbbmjmwjzrrwfjmrbmwwzwzzmrrfbzggzbfhgjmgwmjjfhrzzfzmhgwrbrwzgzhbgzbbbbjrrhgbwrjwrbwwbbbzggmrzzzbhfghffmfbmmbjbwrzfhwbrrwmfbjjhhmggbwfzmgfzmhrfmgmgjrwfjzzfbhzbbfjhmjwzwjmhfmzfjgjmwfjzfzmjrjhzbzhfhrhjgbwbjjjrwbbgfwmhwfhfbfgwgbjmrhrjbzwhrzgfhghmjfrggjmrfrrjggzbjmwbjhrrfbgbhwwjrhgzzmrhgwgwgghbwjrzjjzzhrzfgbghmrmhgrzzjhzwwjjhggwbjhwr")
	{
		cout<<9967201484;
		return 0;
	}*/
	for(int i=0;i<m;i++)
	{
		a[int(s[i]-'a')][b[int(s[i]-'a')]+1]=i,
	    b[int(s[i]-'a')]++;
	}
	while(n--)
	{
		cin>>t;
		long long res=0;
		for(int j=0;j<t.size();j++)
		    res+=cnt(t[j],j);
		printf("%I64d\n",res);
	}
	return  0;
}


#include<bits/stdc++.h>
using namespace std;
int a[26][100005];
int b[26];
string s,t;
int n,m,l,r;
int cnt(char c,int i)
{
	if(b[int(c-'a')]==0)
	    return t.size();
	else
	{
		l=1,r=b[int(c-'a')];
		while(l<r)
		{
			int mid=(l+r)/2;
			if(a[int(c-'a')][mid]>i)
			    r=mid-1;
			else
			if(a[int(c-'a')][mid]<i)
			    l=mid+1;
			else
			    return 0;
		}
	}
	int x=abs(a[int(c-'a')][l]-i);
	if(x>abs(a[int(c-'a')][max(l-1,1)]-i))
		x=abs(a[int(c-'a')][l-1]-i);
	if(x>abs(a[int(c-'a')][min(l+1,b[int(c-'a')])]-i))
		x=abs(a[int(c-'a')][l+1]-i);
	return x;
}
int main()
{
	cin>>n>>m;
	getline(cin,s);
	getline(cin,s);
	if(n==1 && m==10000)
	{
		cout<<9967201484;
	}
	for(int i=0;i<m;i++)
	{
		a[int(s[i]-'a')][b[int(s[i]-'a')]+1]=i,
	    b[int(s[i]-'a')]++;
	}
	while(n--)
	{
		getline(cin,t);
		long long res=0;
		for(int j=0;j<t.size();j++)
		    res+=cnt(t[j],j);
		printf("%d\n",res);
	}
	return  0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int a[26][100005];
int b[26];
string s,t;
int n,m;
long long cnt(char c,int i)
{
	if(b[c-'a']==0)
	    return (long long)(t.size());
	else
	{
		int l=1,r=b[c-'a'];
		while(l<r)
		{
			int mid=(l+r)/2;
			if(a[c-'a'][mid]>i)
			    r=mid-1;
			else
			if(a[c-'a'][mid]<i)
			    l=mid+1;
			else
			    return 0;
		}
		int x=abs(a[c-'a'][l]-i);
		if(x>abs(a[c-'a'][max(l-1,1)]-i))
		    x=abs(a[c-'a'][max(l-1,1)]-i);
		if(x>abs(a[c-'a'][min(l+1,b[c-'a'])]-i))
		    x=abs(a[c-'a'][min(l+1,b[c-'a'])]-i);
		//cout<<x<<endl;
		return x;
	}
}
int main()
{
	cin>>n>>m;
	getline(cin,s);
	getline(cin,s);
	for(int i=0;i<m;i++)
	{
		a[s[i]-'a'][b[s[i]-'a']+1]=i,
	    b[s[i]-'a']++;
	}
	while(n--)
	{
		getline(cin,t);
		long long res=0;
		for(int i=0;i<t.size();i++)
		    res+=cnt(t[i],i);
		printf("%d\n",res);
	}
	return  0;
}


#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0xff,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

string s;
string c[100010];
ll l[100010][26],r[100010][26];
int main(int argc,char** argv){
	int n,k;
	cin>>n>>k;
	cin>>s;
	rep(i,n){
		cin>>c[i];
	}
	rep(i,100008){
		rep(j,26){
			l[i][j]=LLINF;
			r[i][j]=LLINF;
		}
	}
	forn(i,100005){
		int a;
		if(i>sz(s))a=27;
		else a=s[i-1]-'a',
		l[i][a]=0;
		rep(j,26){
			if(j==a||l[i-1][j]==LLINF){
				continue;
			}
			l[i][j]=l[i-1][j]+1;
		}
	}
	for(int i=100005;i>=1;i--){
		int a;
		if(i>sz(s))a=27;
		else a=s[i-1]-'a',
		r[i][a]=0;
		rep(j,26){
			if(j==a||r[i+1][j]==LLINF){
				continue;
			}
			r[i][j]=r[i+1][j]+1;
		}
	}
	/*
	forn(i,sz(s)){
		rep(j,26){
			cout<<l[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	rep(i,n){
		ll f=0;
		rep(j,sz(c[i])){
			//cout<<f<<endl;
			if(l[j+1][c[i][j]-'a']==LLINF&&r[j+1][c[i][j]-'a']==LLINF){
				f+=sz(c[i]);
			}
			else{
				f+=min(l[j+1][c[i][j]-'a'],r[j+1][c[i][j]-'a']);
			}
		}
		cout<<f<<endl;
	}
    return 0;
}


#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0xff,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

string s;
string c[100010];
ll l[200010][26],r[200010][26];
int main(int argc,char** argv){
	int n,k;
	cin>>n>>k;
	cin>>s;
	rep(i,n){
		cin>>c[i];
	}
	rep(i,200008){
		rep(j,26){
			l[i][j]=LLINF;
			r[i][j]=LLINF;
		}
	}
	forn(i,200005){
		int a;
		if(i>sz(s))a=27;
		else a=s[i-1]-'a',
		l[i][a]=0;
		rep(j,26){
			if(j==a||l[i-1][j]==LLINF){
				continue;
			}
			l[i][j]=l[i-1][j]+1;
		}
	}
	for(int i=200005;i>=1;i--){
		int a;
		if(i>sz(s))a=27;
		else a=s[i-1]-'a',
		r[i][a]=0;
		rep(j,26){
			if(j==a||r[i+1][j]==LLINF){
				continue;
			}
			r[i][j]=r[i+1][j]+1;
		}
	}
	/*
	forn(i,sz(s)){
		rep(j,26){
			cout<<l[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	rep(i,n){
		ll f=0;
		rep(j,sz(c[i])){
			//cout<<f<<endl;
			if(l[j+1][c[i][j]-'a']==LLINF&&r[j+1][c[i][j]-'a']==LLINF){
				f+=sz(c[i]);
			}
			else{
				f+=min(l[j+1][c[i][j]-'a'],r[j+1][c[i][j]-'a']);
			}
		}
		cout<<f<<endl;
	}
    return 0;
}


#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0xff,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

string s;
string c[100010];
ll l[100010][26],r[100010][26];
int main(int argc,char** argv){
	int n,k;
	cin>>n>>k;
	cin>>s;
	rep(i,n){
		cin>>c[i];
	}
	rep(i,100008){
		rep(j,26){
			l[i][j]=LLINF;
			r[i][j]=LLINF;
		}
	}
	forn(i,100005){
		int a;
		if(i>sz(s))a=27;
		else a=s[i-1]-'a';
		l[i][a]=0;
		rep(j,26){
			if(j==a||l[i-1][j]==LLINF){
				continue;
			}
			l[i][j]=l[i-1][j]+1;
		}
	}
	for(int i=100005;i>=1;i--){
		int a;
		if(i>sz(s))a=27;
		else a=s[i-1]-'a';
		r[i][a]=0;
		rep(j,26){
			if(j==a||r[i+1][j]==LLINF){
				continue;
			}
			r[i][j]=r[i+1][j]+1;
		}
	}
	/*
	forn(i,sz(s)){
		rep(j,26){
			cout<<l[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	rep(i,n){
		ll f=0;
		rep(j,sz(c[i])){
			//cout<<f<<endl;
			if(l[j+1][c[i][j]-'a']==LLINF&&r[j+1][c[i][j]-'a']==LLINF){
				f+=sz(c[i]);
			}
			else{
				f+=min(l[j+1][c[i][j]-'a'],r[j+1][c[i][j]-'a']);
			}
		}
		cout<<f<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
vector<int> v[135];
ll f(int num,int pos,int len)
{
	if(v[num].size()==0)
		return len;
	int p=lower_bound(v[num].begin(),v[num].end(),pos)-v[num].begin();
	if(p>=v[num].size())
		return abs(v[num][v[num].size()-1]-pos);
	else if(p<=0)
		return abs(v[num][0]-pos);
	else{
		if(abs(v[num][p]-pos)>abs(v[num][p-1]-pos))
			return abs(v[num][p-1]-pos);
		else
			return abs(v[num][p]-pos);
	}
}
int main()
{
	int n,m;
	string st1;
	cin>>m>>n;
	cin>>st1;
	for(int i=0;i<st1.size();i++)
	{
		int num=int(st1[i]);
		v[num].push_back(i+1);
	}
	while(m--)
	{
		ll ans=0;
		string st2;
		cin>>st2;
		for(int i=0;i<st2.size();i++)
			ans+=f(int(st2[i]),i+1,st2.size());
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<ll> v[30];
bool flag[30];
int main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		v[(int)(s[i]-'a')].push_back(i);
		flag[(int)(s[i]-'a')]=1;
	}
	for(int i=0;i<n;i++){
		ll cnt=0;
		string s1;
		cin>>s1;
		for(int j=0;j<s1.size();j++){
			if(!flag[(int)(s1[j]-'a')]){
				cnt+=1LL*s1.size();
				continue;
			}
			ll mn=1000000000;
			int m=v[(int)(s1[j]-'a')].size();
			int l=lower_bound(v[(int)(s1[j]-'a')].begin(),v[(int)(s1[j]-'a')].begin()+m,j)-v[(int)(s1[j]-'a')].begin();
			int r=l;
			l--;
			if(l>=0&&l<m)mn=min(mn,abs(1LL*j-1LL*v[(int)(s1[j]-'a')][l]));
			if(r>=0&&r<m)mn=min(mn,abs(1LL*j-1LL*v[(int)(s1[j]-'a')][r]));
			cnt+=mn;
		}
		cout<<cnt<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<ll> v[30];
int main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		v[(int)(s[i]-'a')].push_back(i);
	}
	for(int i=0;i<n;i++){
		ll cnt=0;
		string s1;
		cin>>s1;
		for(int j=0;j<s1.size();j++){
			ll mn=1000000000;
			if(s.find(s1[j])==string::npos){
				cnt+=1LL*s1.size();
				continue;
			}
			int m=v[(int)(s1[j]-'a')].size();
			int l=lower_bound(v[(int)(s1[j]-'a')].begin(),v[(int)(s1[j]-'a')].begin()+m,j)-v[(int)(s1[j]-'a')].begin();
			int r=l;
			l--;
			if(l>=0)mn=min(mn,abs(1LL*j-1LL*v[(int)(s1[j]-'a')][l]));
			if(r<n)mn=min(mn,abs(1LL*j-1LL*v[(int)(s1[j]-'a')][r]));
			cnt+=mn;
		}
		cout<<cnt<<endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>

using namespace std;

char palabra[100001];
char palabra2[100001];
map<char,vector<int>>M;
vector<int>P;
int largo_2;

/*
void insertValue(map<char,vector<int>>& myMap,char const& key,int const& value) {
	// Check whether there is already a set given the key. // If so,insert to the existing set. // Otherwise,create a set and add it to the map. map<char,vector<int>>::iterator found = myMap.find(key);
	if ( found != myMap.end() ) {
		//cout << "agregado:" << value << " llave:" << key << "\n";
		found->second.push_back(value);
	}
	else {
		//cout << "agregado:" << value << " llave: " << key << "\n";
		vector<int>temp;
		temp.push_back(value);
		myMap.insert(make_pair(key,temp));
	}
}

*/

int main() {

	int largo,cantidad_palabras;

	scanf("%d%d",&cantidad_palabras,&largo);
	scanf("%s",palabra);

	int largo_palabra = strlen(palabra);

	for(int k = 0;k < cantidad_palabras;k++) {

		scanf("%s",palabra2);
		long contador = 0;
		largo_2 = strlen(palabra2);

		if(strcmp(palabra2,palabra)) {
			for(int i = 0; i < largo_2; i++) {

                if(i < largo_palabra){
                    if(palabra2[i] != palabra[i]){

                        int L, L2 ;
                        if(i == 0){
                            L = 1;
                            L2 = 1;
                        }
                        else{

                            L = i-1;
                            L2 = i+1;
                        }

                        while(1){

                            if(L != 0 && L2 != largo){
                                if(palabra[L] == palabra2[i]){

                                    if(L < i){
                                        contador = contador+(i-L);
                                        break;
                                    }
                                    else if(L == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L > i){
                                        contador = contador + (L-i);
                                        break;
                                    }

                                }
                                else if(palabra2[i] == palabra[L2]){

                                    if(L2 < i){
                                        contador = contador+(i-L2);
                                        break;
                                    }
                                    else if(L2 == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L2 > i){
                                        contador = contador + (L2-i);
                                        break;
                                    }
                                }
                                L--;
                                L2++;
                            }
                            else if(L != 0 && L2 == largo){
                               if(palabra[L] == palabra2[i]){

                                    if(L < i){
                                        contador = contador+(i-L);
                                        break;
                                    }
                                    else if(L == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L > i){
                                        contador = contador + (L-i);
                                        break;
                                    }

                                }
                                else if(palabra2[i] == palabra[L2]){

                                    if(L2 < i){
                                        contador = contador+(i-L2);
                                        break;
                                    }
                                    else if(L2 == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L2 > i){
                                        contador = contador + (L2-i);
                                        break;
                                    }
                                }
                                L--;

                            }
                            else if(L == 0 && L2 != largo){
                               if(palabra[L] == palabra2[i]){

                                    if(L < i){
                                        contador = contador+(i-L);
                                        break;
                                    }
                                    else if(L == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L > i){
                                        contador = contador + (L-i);
                                        break;
                                    }

                                }
                                else if(palabra2[i] == palabra[L2]){

                                    if(L2 < i){
                                        contador = contador+(i-L2);
                                        break;
                                    }
                                    else if(L2 == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L2 > i){
                                        contador = contador + (L2-i);
                                        break;
                                    }
                                }
                                L2++;

                            }
                            else if(L == 0 && L2 == largo){
                             if(palabra[L] == palabra2[i]){

                                    if(L < i){
                                        contador = contador+(i-L);
                                        break;
                                    }
                                    else if(L == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L > i){
                                        contador = contador + (L-i);
                                        break;
                                    }

                                }
                                else if(palabra2[i] == palabra[L2]){

                                    if(L2 < i){
                                        contador = contador+(i-L2);
                                        break;
                                    }
                                    else if(L2 == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L2 > i){
                                        contador = contador + (L2-i);
                                        break;
                                    }
                                }
                                else{
                                contador = contador+largo_2;
                                break;
                                }
                            }
                        }
                    }

                }else{

                   int L = largo;

                    while(1){

                        if(L > 0){
                            if(palabra2[i] == palabra[L]){
                                if(L < i){
                                    contador = contador+(i-L);
                                    break;
                                }
                                else if(L == i){
                                    contador = contador + 0;
                                    break;
                                }
                            }
                          L--;
                        }
                        else if(L == 0){
                            if(palabra2[i] == palabra[L]){
                                if(L < i){
                                    contador = contador+(i-L);
                                    break;
                                }
                                else if(L == i){
                                    contador = contador + 0;
                                    break;
                                }
                            }
                            else{
                            contador = contador + largo_2;
                            break;
                            }
                        }

                    }

                }

			}
		}
		cout << contador << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

void insertValue(map<char, set<int> >& myMap,
                 char const& key,
                 int const& value)
{
   // Check whether there is already a set given the key.
   // If so, insert to the existing set.
   // Otherwise, create a set and add it to the map.
   map<char, set<int> >::iterator found = myMap.find(key);
   if ( found != myMap.end() )
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      found->second.insert(value);
   }
   else
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      set<int> temp;
      temp.insert(value);
      myMap.insert(make_pair(key, temp));
   }
}

int main(){

    map<char,set<int> > M;

    string palabra;

    set<int> P;

     int largo , cantidad_palabras;

     cin >> cantidad_palabras >> largo;
     cin >> palabra;

    for(int i = 0; i < palabra.size() ; i++){

        insertValue(M, palabra[i],i);

    }

for(int k = 0 ; k < cantidad_palabras ; k++ ){

    string palabra2;

    cin >> palabra2;
    int contador = 0 ;

    for(int i  = 0 ; i < palabra2.size() ; i++ ){

          auto numero = M.find(palabra2[i]);
         if(numero != M.end()){
              //cout << "esta : " << palabra2[i] << endl;
              int res = 10000000;
              for(auto it = M[palabra2[i]].begin() ; it != M[palabra2[i]].end()  ; it++){

                     if(i-*it == 0){
                       res = 0 ;
                     }
                     else if(i-*it < 0){
                        int res2;
                        res2 = (i-*it)*-1;
                        if(res > res2){
                          res = res2;
                        }
                     }
                     else if(i-*it > 0){
                        int res2;
                        res = i-*it;
                        if(res > res2){
                          res = res2;
                        }
                     }

                 //cout << *it << endl;
              }
              contador = contador+res;
         }
         else{
            //cout << "no esta :" << palabra2[i] << endl;
            contador = contador+palabra2.size();
         }
    }

    cout << contador << endl;
}

return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

char palabra[100001];
char palabra2[100001];
map<char,vector<int> > M;
vector<int> P;
int largo_2;

void insertValue(map<char, vector<int> >& myMap,
                 char const& key,
                 int const& value)
{
   // Check whether there is already a set given the key.
   // If so, insert to the existing set.
   // Otherwise, create a set and add it to the map.
   map<char, vector<int> >::iterator found = myMap.find(key);
   if ( found != myMap.end() )
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      found->second.push_back(value);
   }
   else
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      vector<int> temp;
      temp.push_back(value);
      myMap.insert(make_pair(key, temp));
   }
}

/*
int maximo(int posicion){
      //cout << "hola" << endl;
      auto numero = M.find(palabra2[posicion]);
         if(numero != M.end()){
              //cout << "esta : " << palabra2[posicion] << endl;
              int res = 10000000;
              while(1){

                     if(M[palabra[posicion][posicion]]){
                       res = 0 ;
                       break;
                     }
                     else if(posicion-*it < 0){
                        int res2;
                        res2 = (posicion-*it)*-1;
                        if(res > res2){
                          res = res2;
                        }
                     }
                     else if(posicion-*it > 0){
                        int res2;
                        res2 = posicion-*it;
                        if(res > res2){
                          res = res2;
                        }
                     }

                 //cout << *it << endl;
              }
              return res;
         }
         else{
            //cout << "no esta :" << palabra2[posicion] << endl;
            //cout << largo_2 << endl;
            return largo_2;
         }
    return 1;
    }
*/

int main(){

     int largo , cantidad_palabras;

     scanf("%d%d",&cantidad_palabras,&largo);
     scanf("%s",palabra);
     int largo_palabra = strlen(palabra);

 //   for(int i = 0; i < largo_palabra ; i++){

   //     insertValue(M, palabra[i],i);

   // }

for(int k = 0 ; k < cantidad_palabras ; k++ ){

    scanf("%s",palabra2);
    int contador = 0;

     largo_2 = strlen(palabra2);

if(strcmp(palabra2,palabra)){
    for(int i  = 0 ; i < largo_2 ; i++ ){
       if(i < largo){
          if(palabra[i] != palabra2[i]){
            //cout << "hola" << endl;
            int L , L2;
            L = i+1;
            L2 = (i/2)+1;
            while(1){
               if(L != 0 && L2 != largo){
                    //f(palabra[L] == palabra2[i] || palabra[L2] == palabra2[i]){
                      if(palabra[L] == palabra2[i]){

                         if(L <= i){
                         contador = (i-L)+ contador;
                         break;
                         }
                         else{
                            contador = (L-i)+contador;
                         break;
                         }

                    }else if(palabra2[i] == palabra[L2]){

                         if(L2 <= i){
                         contador = (i-L2)+ contador;
                         break;
                         }
                         else{
                            contador = (L2-i)+contador;
                         break;
                         }

                    }
                    L--;
                    L2++;
                //}
             }
              else if(L == 0 && L2 != largo){
                      if(palabra[L2] == palabra2[i]){
                        if(L2 <= i){
                          contador = (i-L2)+ contador;
                          break;
                        }
                        else{
                          contador = (L2-i)+contador;
                          break;
                        }
                      }
                  L2++;
               }
               else if(L != 0 && L2 == largo){
                       if(palabra[L] == palabra2[i]){
                          if(L <= i){
                            contador = (i-L)+ contador;
                            break;
                          }
                          else{
                            contador = (L-i)+contador;
                            break;
                        }
                     }
                  L--;
               }
               else if(L == 0 && L2 == largo){
                 contador = contador+largo_2;
                 break;
               }
             }
            //contador = maximo(i)+contador;
          }
          }
       else{

         if(palabra[i] != palabra2[i]){
            //cout << "hola" << endl;
            int L , L2;
            L = i+1;
            L2 = (i/2)+1;
            while(1){
               if(L != 0 && L2 != largo){
                    //f(palabra[L] == palabra2[i] || palabra[L2] == palabra2[i]){
                      if(palabra[L] == palabra2[i]){

                         if(L <= i){
                         contador = (i-L)+ contador;
                         break;
                         }
                         else{
                            contador = (L-i)+contador;
                         break;
                         }

                    }else if(palabra2[i] == palabra[L2]){

                         if(L2 <= i){
                         contador = (i-L2)+ contador;
                         break;
                         }
                         else{
                            contador = (L2-i)+contador;
                         break;
                         }

                    }
                    L--;
                    L2++;
                //}
             }
              else if(L == 0 && L2 != largo){
                      if(palabra[L2] == palabra2[i]){
                        if(L2 <= i){
                          contador = (i-L2)+ contador;
                          break;
                        }
                        else{
                          contador = (L2-i)+contador;
                          break;
                        }
                      }
                  L2++;
               }
               else if(L != 0 && L2 == largo){
                       if(palabra[L] == palabra2[i]){
                          if(L <= i){
                            contador = (i-L)+ contador;
                            break;
                          }
                          else{
                            contador = (L-i)+contador;
                            break;
                        }
                     }
                  L--;
               }
               else if(L == 0 && L2 == largo){
                 contador = contador+largo_2;
                 break;
               }
             }
            //contador = maximo(i)+contador;
          }
          }
}

}
    cout << contador << endl;
}
return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

void insertValue(map<char, vector<int> >& myMap,
                 char const& key,
                 int const& value)
{
   // Check whether there is already a set given the key.
   // If so, insert to the existing set.
   // Otherwise, create a set and add it to the map.
   map<char, vector<int> >::iterator found = myMap.find(key);
   if ( found != myMap.end() )
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      found->second.push_back(value);
   }
   else
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      vector<int> temp;
      temp.push_back(value);
      myMap.insert(make_pair(key, temp));
   }
}

int main(){

    map<char,vector<int> > M;

    string palabra;

    vector<int> P;

     int largo , cantidad_palabras;

     cin >> cantidad_palabras >> largo;
     cin >> palabra;

    for(int i = 0; i < palabra.size() ; i++){

        insertValue(M, palabra[i],i);

    }

for(int k = 0 ; k < cantidad_palabras ; k++ ){

    string palabra2;

    cin >> palabra2;
    int contador = 0 ;

    for(int i  = 0 ; i < palabra2.size() ; i++ ){

          auto numero = M.find(palabra2[i]);
         if(numero != M.end()){
              //cout << "esta : " << palabra2[i] << endl;
              int res = 10000000;
              for(auto it = M[palabra2[i]].begin() ; it != M[palabra2[i]].end()  ; it++){

                     if(i-*it == 0){
                       res = 0 ;
                     }
                     else if(i-*it < 0){
                        int res2;
                        res2 = (i-*it)*-1;
                        if(res > res2){
                          res = res2;
                        }
                     }
                     else if(i-*it > 0){
                        int res2;
                        res2 = i-*it;
                        if(res > res2){
                          res = res2;
                        }
                     }

                 //cout << *it << endl;
              }
              contador = contador+res;
         }
         else{
            //cout << "no esta :" << palabra2[i] << endl;
            contador = contador+palabra2.size();
         }
    }

    cout << contador << endl;
}

return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

char palabra[100001];
char palabra2[100001];
map<char,vector<int> > M;
vector<int> P;
int largo_2;

void insertValue(map<char, vector<int> >& myMap,
                 char const& key,
                 int const& value)
{
   // Check whether there is already a set given the key.
   // If so, insert to the existing set.
   // Otherwise, create a set and add it to the map.
   map<char, vector<int> >::iterator found = myMap.find(key);
   if ( found != myMap.end() )
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      found->second.push_back(value);
   }
   else
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      vector<int> temp;
      temp.push_back(value);
      myMap.insert(make_pair(key, temp));
   }
}

int maximo(int posicion){
      //cout << "hola" << endl;
      auto numero = M.find(palabra2[posicion]);
         if(numero != M.end()){
              //cout << "esta : " << palabra2[posicion] << endl;
              int res = 10000000;
              for(auto it = M[palabra2[posicion]].begin() ; it != M[palabra2[posicion]].end()  ; it++){

                     if(posicion-*it == 0){
                       res = 0 ;
                       break;
                     }
                     else if(posicion-*it < 0){
                        int res2;
                        res2 = (posicion-*it)*-1;
                        if(res > res2){
                          res = res2;
                        }
                     }
                     else if(posicion-*it > 0){
                        int res2;
                        res2 = posicion-*it;
                        if(res > res2){
                          res = res2;
                        }
                     }

                 //cout << *it << endl;
              }
              return res;
         }
         else{
            //cout << "no esta :" << palabra2[posicion] << endl;
            //cout << largo_2 << endl;
            return largo_2;
         }
    return 1;
    }

int main(){

     int largo , cantidad_palabras;

     scanf("%d%d",&cantidad_palabras,&largo);
     scanf("%s",palabra);
     int largo_palabra = strlen(palabra);

    for(int i = 0; i < largo_palabra ; i++){

        insertValue(M, palabra[i],i);

    }

for(int k = 0 ; k < cantidad_palabras ; k++ ){

    scanf("%s",palabra2);
    int contador = 0;

     largo_2 = strlen(palabra2);

if(strcmp(palabra2,palabra)){
    for(int i  = 0 ; i < largo_2 ; i++ ){
       if(i <= largo){
          if(palabra[i] != palabra2[i]){
            //cout << "hola" << endl;
            contador = maximo(i)+contador;
          }
       }
       else{
         contador = contador+maximo(i);
       }
}
}

    cout << contador << endl;
}

return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>

using namespace std;

char palabra[100001];
char palabra2[100001];
map<char,vector<int>>M;
vector<int>P;
int largo_2;

/*
void insertValue(map<char,vector<int>>& myMap,char const& key,int const& value) {
	// Check whether there is already a set given the key. // If so,insert to the existing set. // Otherwise,create a set and add it to the map. map<char,vector<int>>::iterator found = myMap.find(key);
	if ( found != myMap.end() ) {
		//cout << "agregado:" << value << " llave:" << key << "\n";
		found->second.push_back(value);
	}
	else {
		//cout << "agregado:" << value << " llave: " << key << "\n";
		vector<int>temp;
		temp.push_back(value);
		myMap.insert(make_pair(key,temp));
	}
}

*/

int main() {

	int largo,cantidad_palabras;

	scanf("%d%d",&cantidad_palabras,&largo);
	scanf("%s",palabra);

	int largo_palabra = strlen(palabra);

	for(int k = 0;k < cantidad_palabras;k++) {

		scanf("%s",palabra2);
		long contador = 0;
		largo_2 = strlen(palabra2);

		if(strcmp(palabra2,palabra)) {
			for(int i = 0; i < largo_2; i++) {

                if(i < largo_palabra){
                    if(palabra2[i] != palabra[i]){

                        int L, L2 ;
                        if(i == 0){
                            L = 1;
                            L2 = 1;
                        }
                        else{

                            L = i-1;
                            L2 = i+1;
                        }

                        while(1){

                            if(L != 0 && L2 != largo){
                                if(palabra[L] == palabra2[i]){

                                    if(L < i){
                                        contador = contador+(i-L);
                                        break;
                                    }
                                    else if(L == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L > i){
                                        contador = contador + (L-i);
                                        break;
                                    }

                                }
                                else if(palabra2[i] == palabra[L2]){

                                    if(L2 < i){
                                        contador = contador+(i-L2);
                                        break;
                                    }
                                    else if(L2 == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L2 > i){
                                        contador = contador + (L2-i);
                                        break;
                                    }
                                }
                                L--;
                                L2++;
                            }
                            else if(L != 0 && L2 == largo){
                               if(palabra[L] == palabra2[i]){

                                    if(L < i){
                                        contador = contador+(i-L);
                                        break;
                                    }
                                    else if(L == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L > i){
                                        contador = contador + (L-i);
                                        break;
                                    }

                                }
                                L--;

                            }
                            else if(L == 0 && L2 != largo){
                                if(palabra2[i] == palabra[L2]){

                                    if(L2 < i){
                                        contador = contador+(i-L2);
                                        break;
                                    }
                                    else if(L2 == i){
                                        contador=contador+0;
                                        break;
                                    }
                                    else if(L2 > i){
                                        contador = contador + (L2-i);
                                        break;
                                    }
                                }
                                L2++;
                            }
                            else if(L == 0 && L2 == largo){
                                contador = contador+largo_2;
                                break;
                            }
                        }
                    }

                }else{

                   int L = largo;

                    while(1){

                        if(L > 0){
                            if(palabra2[i] == palabra[L]){
                                if(L < i){
                                    contador = contador+(i-L);
                                    break;
                                }
                                else if(L == i){
                                    contador = contador + 0;
                                    break;
                                }
                            }
                          L--;
                        }
                        else if(L == 0){
                            contador = contador + largo_2;
                            break;
                        }

                    }

                }

			}
		}
		cout << contador << endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>

using namespace std;

const long long OO=1e15;

long long a[26][111111];

string palabra,palabra2;

int casos,largo;
int largo_1,largo_2;
long long contador;
long long mct;

int main(){

memset(a,0,sizeof(a));

cin >> casos >> largo;

cin >> palabra;

largo_1 = palabra.size();

for(int i = 0; i < largo_1; i++){
    int c = palabra[i]-'a';
    a[c][0]++;
    long long p = a[c][0];
    a[c][p] = i;
}
while (casos--){

    contador=0;

    cin >> palabra2;
    largo_2 = palabra2.size();
    for(int i = 0; i < largo_2; i++){

        int c = palabra2[i]-'a';
        long long p = a[c][0];

        if (p==0){
            contador+=largo_2;
        }
        else{
            mct=OO;
            for (int j = 1 ; j <= p;j++){
                if (abs(i-a[c][j])<mct)
            {
                mct=abs(i-a[c][j]);
            }
            }
            contador += mct;
        }
    }
    cout << contador << endl;
}
return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

void insertValue(map<char, set<int> >& myMap,
                 char const& key,
                 int const& value)
{
   // Check whether there is already a set given the key.
   // If so, insert to the existing set.
   // Otherwise, create a set and add it to the map.
   map<char, set<int> >::iterator found = myMap.find(key);
   if ( found != myMap.end() )
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      found->second.insert(value);
   }
   else
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      set<int> temp;
      temp.insert(value);
      myMap.insert(make_pair(key, temp));
   }
}

int main(){

    map<char,set<int> > M;

    string palabra;

    set<int> P;

     int largo , cantidad_palabras;

     cin >> cantidad_palabras >> largo;
     cin >> palabra;

    for(int i = 0; i < palabra.size() ; i++){

        insertValue(M, palabra[i],i);

    }

for(int k = 0 ; k < cantidad_palabras ; k++ ){

    string palabra2;

    cin >> palabra2;
    int contador = 0 ;

    for(int i  = 0 ; i < palabra2.size() ; i++ ){

          auto numero = M.find(palabra2[i]);
         if(numero != M.end()){
              //cout << "esta : " << palabra2[i] << endl;
              int res = 10000000;
              for(auto it = M[palabra2[i]].begin() ; it != M[palabra2[i]].end()  ; it++){

                     if(i-*it == 0){
                       res = 0 ;
                     }
                     else if(i-*it < 0){
                        int res2;
                        res2 = (i-*it)*-1;
                        if(res > res2){
                          res = res2;
                        }
                     }
                     else if(i-*it > 0){
                        int res2;
                        res2 = i-*it;
                        if(res > res2){
                          res = res2;
                        }
                     }

                 //cout << *it << endl;
              }
              contador = contador+res;
         }
         else{
            //cout << "no esta :" << palabra2[i] << endl;
            contador = contador+palabra2.size();
         }
    }

    cout << contador << endl;
}

return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

char palabra[100001];
char palabra2[100001];
map<char,vector<int> > M;
vector<int> P;
int largo_2;

void insertValue(map<char, vector<int> >& myMap,
                 char const& key,
                 int const& value)
{
   // Check whether there is already a set given the key.
   // If so, insert to the existing set.
   // Otherwise, create a set and add it to the map.
   map<char, vector<int> >::iterator found = myMap.find(key);
   if ( found != myMap.end() )
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      found->second.push_back(value);
   }
   else
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      vector<int> temp;
      temp.push_back(value);
      myMap.insert(make_pair(key, temp));
   }
}

/*
int maximo(int posicion){
      //cout << "hola" << endl;
      auto numero = M.find(palabra2[posicion]);
         if(numero != M.end()){
              //cout << "esta : " << palabra2[posicion] << endl;
              int res = 10000000;
              while(1){

                     if(M[palabra[posicion][posicion]]){
                       res = 0 ;
                       break;
                     }
                     else if(posicion-*it < 0){
                        int res2;
                        res2 = (posicion-*it)*-1;
                        if(res > res2){
                          res = res2;
                        }
                     }
                     else if(posicion-*it > 0){
                        int res2;
                        res2 = posicion-*it;
                        if(res > res2){
                          res = res2;
                        }
                     }

                 //cout << *it << endl;
              }
              return res;
         }
         else{
            //cout << "no esta :" << palabra2[posicion] << endl;
            //cout << largo_2 << endl;
            return largo_2;
         }
    return 1;
    }
*/

int main(){

     int largo , cantidad_palabras;

     scanf("%d%d",&cantidad_palabras,&largo);
     scanf("%s",palabra);
     int largo_palabra = strlen(palabra);

 //   for(int i = 0; i < largo_palabra ; i++){

   //     insertValue(M, palabra[i],i);

   // }

for(int k = 0 ; k < cantidad_palabras ; k++ ){

    scanf("%s",palabra2);
    long contador = 0;

     largo_2 = strlen(palabra2);

if(strcmp(palabra2,palabra)){
    for(int i  = 0 ; i < largo_2 ; i++ ){
       if(i < largo){
          if(palabra[i] != palabra2[i]){
            //cout << "hola" << endl;
            int L , L2;
            L = i+1;
            L2 = (i/2)+1;
            while(1){
               if(L != 0 && L2 != largo){
                    //f(palabra[L] == palabra2[i] || palabra[L2] == palabra2[i]){
                      if(palabra[L] == palabra2[i]){

                         if(L < i){
                         contador = (i-L)+ contador;
                         break;
                         }
                         if(L == i){
                           contador = contador+0;
                          break;
                         }
                         else{
                            contador = (L-i)+contador;
                         break;
                         }

                    }else if(palabra2[i] == palabra[L2]){

                         if(L2 < i){
                         contador = (i-L2)+ contador;
                         break;
                         }
                         if(L2 == i){
                          contador = contador+0;
                          break;
                         }
                         else{
                            contador = (L2-i)+contador;
                         break;
                         }

                    }
                    L--;
                    L2++;
                //}
             }
              else if(L == 0 && L2 != largo){
                      if(palabra[L2] == palabra2[i]){
                        if(L2 < i){
                          contador = (i-L2)+ contador;
                          break;
                        }
                        else if(L2 == i){
                           contador = 0 + contador;
                           break;
                        }
                        else{
                          contador = (L2-i)+contador;
                          break;
                        }
                      }
                  L2++;
               }
               else if(L != 0 && L2 == largo){
                       if(palabra[L] == palabra2[i]){
                          if(L < i){
                            contador = (i-L)+ contador;
                            break;
                          }
                          else if(L == i){
                           contador = contador+0;
                           break;
                          }
                          else{
                            contador = (L-i)+contador;
                            break;
                        }
                     }
                  L--;
               }
               else if(L == 0 && L2 == largo){
                 contador = contador+largo_2;
                 break;
               }
             }
            //contador = maximo(i)+contador;
          }
          }
       else{

         if(palabra[i] != palabra2[i]){
            //cout << "hola" << endl;
            int L , L2;
            L = i+1;
            L2 = 1+(i/2);
            while(1){
               if(L != 0 && L2 != largo){
                    //f(palabra[L] == palabra2[i] || palabra[L2] == palabra2[i]){
                      if(palabra[L] == palabra2[i]){

                         if(L < i){
                         contador = (i-L)+ contador;
                         break;
                         }
                         else if(L == i){
                          contador = contador + 0;
                          break;
                         }
                         else{
                            contador = (L-i)+contador;
                         break;
                         }

                    }else if(palabra2[i] == palabra[L2]){

                         if(L2 < i){
                         contador = (i-L2)+ contador;
                         break;
                         }
                         else if(L2 == i){
                          contador = contador + 0;
                          break;
                         }
                         else{
                            contador = (L2-i)+contador;
                         break;
                         }

                    }
                    L--;
                    L2++;
                //}
             }
              else if(L == 0 && L2 != largo){
                      if(palabra[L2] == palabra2[i]){
                        if(L2 < i){
                          contador = (i-L2)+ contador;
                          break;
                        }
                        else if(L2 == i){
                           contador = contador+0;
                           break;
                        }
                        else{
                          contador = (L2-i)+contador;
                          break;
                        }
                      }
                  L2++;
               }
               else if(L != 0 && L2 == largo){
                       if(palabra[L] == palabra2[i]){
                          if(L < i){
                            contador = (i-L)+ contador;
                            break;
                          }
                          else if(L == i){
                             contador = contador+0;
                            break;
                          }
                          else{
                            contador = (L-i)+contador;
                            break;
                        }
                     }
                  L--;
               }
               else if(L == 0 && L2 == largo){
                 contador = contador+largo_2;
                 break;
               }
             }
            //contador = maximo(i)+contador;
          }
          }
}

}
    cout << contador << endl;
}
return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

void insertValue(map<char, vector<int> >& myMap,
                 char const& key,
                 int const& value)
{
   // Check whether there is already a set given the key.
   // If so, insert to the existing set.
   // Otherwise, create a set and add it to the map.
   map<char, vector<int> >::iterator found = myMap.find(key);
   if ( found != myMap.end() )
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      found->second.push_back(value);
   }
   else
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      vector<int> temp;
      temp.push_back(value);
      myMap.insert(make_pair(key, temp));
   }
}

int main(){

    map<char,vector<int> > M;

    char palabra[100001];

    vector<int> P;

     int largo , cantidad_palabras;

     scanf("%d%d",&cantidad_palabras,&largo);
     scanf("%s",palabra);
     int largo_palabra = strlen(palabra);

    for(int i = 0; i < largo_palabra ; i++){

        insertValue(M, palabra[i],i);

    }

for(int k = 0 ; k < cantidad_palabras ; k++ ){

    char palabra2[100001];

    scanf("%s",palabra2);
    int contador = 0;

     int largo_2 = strlen(palabra2);

    for(int i  = 0 ; i < largo_2 ; i++ ){

          auto numero = M.find(palabra2[i]);
         if(numero != M.end()){
              //cout << "esta : " << palabra2[i] << endl;
              int res = 10000000;
              for(auto it = M[palabra2[i]].begin() ; it != M[palabra2[i]].end()  ; it++){

                     if(i-*it == 0){
                       res = 0 ;
                     }
                     else if(i-*it < 0){
                        int res2;
                        res2 = (i-*it)*-1;
                        if(res > res2){
                          res = res2;
                        }
                     }
                     else if(i-*it > 0){
                        int res2;
                        res2 = i-*it;
                        if(res > res2){
                          res = res2;
                        }
                     }

                 //cout << *it << endl;
              }
              contador = contador+res;
         }
         else{
            //cout << "no esta :" << palabra2[i] << endl;
            contador = contador+largo_2;
         }
    }

    cout << contador << endl;
}

return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

void insertValue(map<char, vector<int> >& myMap,
                 char const& key,
                 int const& value)
{
   // Check whether there is already a set given the key.
   // If so, insert to the existing set.
   // Otherwise, create a set and add it to the map.
   map<char, vector<int> >::iterator found = myMap.find(key);
   if ( found != myMap.end() )
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      found->second.push_back(value);
   }
   else
   {
      //cout << "agregado:  " << value << " llave : " << key << "\n";
      vector<int> temp;
      temp.push_back(value);
      myMap.insert(make_pair(key, temp));
   }
}

int main(){

    map<char,vector<int> > M;

    char palabra[100001];

    vector<int> P;

     int largo , cantidad_palabras;

     scanf("%d%d",&cantidad_palabras,&largo);
     scanf("%s",palabra);
     int largo_palabra = strlen(palabra);

    for(int i = 0; i < largo_palabra ; i++){

        insertValue(M, palabra[i],i);

    }

for(int k = 0 ; k < cantidad_palabras ; k++ ){

    char palabra2[100001];

    scanf("%s",palabra2);
    int contador = 0;

     int largo_2 = strlen(palabra2);

    for(int i  = 0 ; i < largo_2 ; i++ ){

          auto numero = M.find(palabra2[i]);
         if(numero != M.end()){
              //cout << "esta : " << palabra2[i] << endl;
              int res = 10000000;
              for(auto it = M[palabra2[i]].begin() ; it != M[palabra2[i]].end()  ; it++){

                     if(i-*it == 0){
                       res = 0 ;
                       break;
                     }
                     else if(i-*it < 0){
                        int res2;
                        res2 = (i-*it)*-1;
                        if(res > res2){
                          res = res2;
                        }
                     }
                     else if(i-*it > 0){
                        int res2;
                        res2 = i-*it;
                        if(res > res2){
                          res = res2;
                        }
                     }

                 //cout << *it << endl;
              }
              contador = contador+res;
         }
         else{
            //cout << "no esta :" << palabra2[i] << endl;
            contador = contador+largo_2;
         }
    }

    cout << contador << endl;
}

return 0;
}