import scala.math.{min,max}

object Main {
  val sc = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    while(true) {
      val n = sc.nextInt
      if(n == 0) return 
      val conv = (1 to n).map(_ => sc.next -> sc.next).toMap
      val m = sc.nextInt
      val ans = (1 to m).map({_ => 
        val c = sc.next
        conv.getOrElse(c, c)
      }).mkString("")
      println(ans)
    }
  }
}