import scala.annotation.tailrec
import scala.io.StdIn._



object Main extends App {

  solve()
  @tailrec def solve(): Unit = {
    val x = readLine.trim
    if (x == "#") return
    val y = readLine.trim
    val add = readInt()
    val erase = readInt()
    val swap = readInt()
    val roll = readInt()
    println(
      x.indices.map{i ⇒ i * roll + minDistance(x.substring(i) + x.substring(0, i), y, x.length - i, add, erase, swap, roll)}.min
    )
    solve()
  }
  def minDistance(from: String, to: String, original: Int, add: Int, erase: Int, swap: Int, roll: Int): Int = {
    val memo = Array.tabulate(2){i ⇒ if (i == 1) Array.tabulate(to.length + 1){j ⇒ j * add} else Array.fill(to.length + 1){Int.MaxValue}}
    for (i ← from.indices) {
      val e = if (i >= original) erase - roll else erase
      memo(i % 2)(0) = memo((i + 1) % 2)(0) + e
      for (j ← to.indices) {
        memo(i % 2)(j + 1) = if (from(i) == to(j)) List(memo((i + 1) % 2)(j) + Math.min(0, Math.min(swap, add + e)), memo(i % 2)(j) + add, memo((i + 1) % 2)(j + 1) + e).min else List(memo((i + 1) % 2)(j) + Math.min(swap, add + e), memo(i % 2)(j) + add, memo((i + 1) % 2)(j + 1) + e).min
        //println(s"minCost from: ${from.substring(0, i + 1)}, to: ${to.substring(0, j + 1)} => ${memo(i % 2)(j + 1)}")
      }
    }

    memo((from.length + 1) % 2).last
  }
}
