### constant

MAX_WLEN = 20
A = 65

### subroutines

def dcword(w)
  #p [w, $tbl]
  w.split('').map{|ch| (A + $tbl[ch.ord - A]).chr}.join('')
end

def decipher(k)
  if k >= $nus
    if $ptxt.nil?
      $ptxt = $seq.map{|w| dcword(w)}.join(' ')
      return
    end
    $ptxt = '-'
    return
  end

  usw = $useq[k]
  uslen = usw.length

  for word in $words[uslen]
    ok = true
    rpl = []

    for i in (0...uslen)
      uswi = usw[i].ord - A
      wi = word[i].ord - A
      if $tbl[uswi].nil? && $tbl[wi].nil?
        rpl << uswi
        $tbl[uswi] = wi
        if uswi != wi
          rpl << wi
          $tbl[wi] = uswi
        end
      elsif $tbl[uswi] != wi
        ok = false
        break
      end
    end

    if ok
      decipher(k + 1)
      return if $ptxt == '-'
    end

    rpl.each{|i| $tbl[i] = nil}
  end
end

### main

loop do
  n = gets.to_i
  break if n == 0

  $words = Array.new(MAX_WLEN + 1){[]}
  n.times do
    w = gets.strip
    $words[w.length] << w
  end

  $seq = gets.strip.delete('.').split
  $useq = $seq.sort{|a, b| b.length <=> a.length}.uniq
  $nus = $useq.length
  #p $words
  #p $useq

  $tbl = Array.new(26){nil}
  $ptxt = nil

  decipher(0)

  puts $ptxt + '.'
end