#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 105


ll A,E,S,R;
ll dp[SIZE][SIZE];
char X[SIZE],Y[SIZE],work_X[SIZE];

void func(){

	scanf("%s",Y);

	scanf("%lld",&A);
	scanf("%lld",&E);
	scanf("%lld",&S);
	scanf("%lld",&R);

	int len_X,len_Y;

	for(len_X = 0; X[len_X] != '\0'; len_X++);
	for(len_Y = 0; Y[len_Y] != '\0'; len_Y++);

	ll ans = HUGE_NUM;

	for(int start = 0; start <= len_X-1; start++){

		for(int i = 0; i < len_X; i++){
			work_X[i] = X[(start+i)%len_X];
		}

		for(int row = 0; row <= len_Y; row++){
			for(int col = 0; col <= len_X; col++){
				dp[row][col] = HUGE_NUM;
			}
		}

		dp[0][0] = 0;

		for(ll col = 1; col <= len_X; col++){
			if(col <= len_X-start){
				dp[0][col] = dp[0][col-1]+E;
			}else{
				dp[0][col] = dp[0][col-1]+E-R;
			}
		}

		for(ll row = 1; row <= len_Y; row++){
			dp[row][0] = A*row;
		}


		ll cost,calc_E;

		for(int row = 1; row <= len_Y; row++){
			for(int col = 1; col <= len_X; col++){
				if(work_X[col-1] == Y[row-1]){
					cost = 0;
				}else{
					cost = S;
				}
				if(col <= len_X-start){

					calc_E = E;

				}else{

					calc_E = E-R;
				}
				dp[row][col] = min(dp[row-1][col-1]+cost,min(dp[row-1][col]+A,dp[row][col-1]+calc_E));
			}
		}

		ans = min(ans,dp[len_Y][len_X]+R*start);
	}

	printf("%lld\n",ans);
}


int main(){

	while(true){

		scanf("%s",X);
		if(X[0] == '#')break;

		func();
	}

	return 0;
}

