### constant

INF = 1 << 30

### subroutines

def sed(str, a, b)
  pos = 0
  str0 = ''
  while pos < str.length
    if str[pos, a.length] == a
      str0 += b
      pos += a.length
    else
      str0 += str[pos]
      pos += 1
    end
  end
  str0
end

### main

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

  substs = n.times.map{gets.strip.split}
  st = gets.strip
  gl = gets.strip
  #p substs
  #p [st, gl]

  dists = Hash.new{INF}
  dists[st] = 0

  q = [st]
  glen = gl.length
  
  while ! q.empty?
    u = q.shift
    break if u == gl

    nvd = dists[u] + 1
    
    substs.each do |a, b|
      v = sed(u, a, b)
      if v.length <= glen && dists[v] >= INF
        dists[v] = nvd
        q << v
      end
    end
  end

  puts (dists[gl] >= INF ? -1 : dists[gl])
end