object Main extends App {
  override def main(args: Array[String]): Unit = {
    import scala.io.{StdIn => in}

    Iterator.continually(in.readInt).takeWhile(_ != 0)
      .map(n => for (i <- 1 to n) yield in.readLine())
      .map(candidates => new Solver(candidates.toArray, in.readLine()))
      .map(_.solve())
      .foreach(println)

  }
}

class Solver(candidates_ : Array[String], val target: String) {
  val answers = target.substring(0, target.size - 1).split(" ").distinct.sortWith((x, y) => x.distinct.length > y.distinct.length)
  val candidates = candidates_.sortWith((x, y) => x.distinct.length > y.distinct.length)

  def solve(): String = {

    val answersSize: Int = answers.size;

    def getMatch(pointer: Int, map: Map[Char, Char], ans: Map[Char, Char], found: Int): (Map[Char, Char], Int) = {
      if (found > 1) (Map[Char, Char](), 2)
      else
        pointer match {
          case `answersSize` => (map, found + 1)
          case _ =>
            if(answers(pointer).forall(map.isDefinedAt(_)))
              if(candidates contains answers(pointer).map(map(_).toUpper)) getMatch(pointer + 1, map, ans, found)
              else (ans,found)
            else (0 until candidates.size)
              .filter(!candidates(_).forall(map.isDefinedAt(_)))
              .filter(candidates(_).length == answers(pointer).length)
              .map(getNewMap(pointer, map, _))
              .collect({ case Some(x: Map[Char, Char]) => x })
              .foldLeft(ans, found)((f, next) => getMatch(pointer + 1, next, f._1, f._2))
        }
    }

    def getNewMap(pointer: Int, map: Map[Char, Char], index: Int): Option[Map[Char, Char]] = {
      val nextAnswer = answers(pointer)
      val nextCandidate = candidates(index)

      val newMap = nextAnswer.zip(nextCandidate).foldLeft((true, map)) { (z, ansCand) =>
        if (!z._1) {
          (false, z._2)
        } else {
          ansCand match {
            case (answer: Char, candidate: Char) if z._2.isDefinedAt(answer) && z._2.isDefinedAt(candidate) => (z._2(answer).toUpper == candidate, z._2)
            case (answer: Char, candidate: Char) if (!z._2.isDefinedAt(answer)) && (!z._2.isDefinedAt(candidate)) => (true, z._2 + (candidate -> answer.toLower, answer -> candidate.toLower))
            case _ => (false, z._2)
          }
        }
      }

      if (newMap._1) Some(newMap._2) else None
    }
    val res = getMatch(0, Map[Char, Char](), Map[Char, Char](), 0)
    if (res._2 == 1) target.map(c => res._1.getOrElse(c, c)).toUpperCase() else "-."
  }
}