class UnionFind
	def initialize
		@obj_to_node = {}
	end

	def add(obj)
		@obj_to_node[obj] ||= Node.new(obj)
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@dw = 0
		end

		def root_and_dw
			return [self, 0] if @parent == self
			r, dw = @parent.root_and_dw
			[@parent = r, @dw += dw]
		end	

		attr_accessor :parent, :dw
	end

	def union(x, y, dw0)
		u, dw1 = (@obj_to_node[x] ||= Node.new(x)).root_and_dw
		v, dw2 = (@obj_to_node[y] ||= Node.new(y)).root_and_dw
		return if u == v
		v.parent, v.dw = u, dw0 + dw1 - dw2
	end

	def weight_diff(x, y)
		return nil unless u = @obj_to_node[x]
		return nil unless v = @obj_to_node[y]
		r1, dw1 = u.root_and_dw
		r2, dw2 = v.root_and_dw
		return nil if r1 != r2
		dw2 - dw1
	end
end


loop do
	n, m = gets.split.map &:to_i
	break if n == 0
	uf = UnionFind.new

	m.times do
		q, a, b, dw = gets.chomp.split
		if q == ?!
			dw = dw.to_i
			uf.union(a, b, dw)
		else
			dw = uf.weight_diff(a, b)
			puts dw ? dw : 'UNKNOWN'
		end
	end
end