import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)

    var n = sc.nextInt
    while (n != 0) {
      val dict = (0 until n).map(_ => (sc.next, sc.next)).toMap
      (0 until sc.nextInt).foreach(_ => {
        val s = sc.next
        print(dict.getOrElse(s, s))
      })
      println()

      n = sc.nextInt
    }
    sc.close()
  }
}