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

	unit_system = []
	ok = true
	n.times {
		gets.chomp =~ /^1 (\w+) = 10\^(-?\d+) (\w+)/
		next unless ok
		u1, x, u2 = $1, $2.to_i, $3
		us1 = unit_system.find{|us| us[u1]}
		us2 = unit_system.find{|us| us[u2]}
		if !us1 && !us2
			unit_system << {u1 => 0, u2 => x}
		elsif !us1
			us2[u1] = us2[u2] - x	
		elsif !us2
			us1[u2] = us1[u1] + x	
		elsif us1 == us2
			if us1[u1] + x != us2[u2]
				ok = false
			end
		else
			unit_system.delete(us2)
			us2.each{|u3, pos|
				y = pos - us2[u2]
				us1[u3] = us1[u1] + x + y
			}
		end
	}
	puts ok ? 'Yes' : 'No'
}