def warshall_floyd(dist_matrix)
	dist = dist_matrix
	n = dist.size
	raise "dist_matrix is not square" if dist.any?{|row| row.size != n}

	next_dist = (1..n).map{ Array.new(n) }	
	(0..n-1).each{|k|
		dist_k = dist[k]
		(0..n-1).each{|i|
			dist_i = dist[i]
			next_dist_i = next_dist[i]
			(0..n-1).each{|j|
				x = dist_i[j]
				y = dist_i[k] + dist_k[j]
				next_dist_i[j] = (x < y ? x : y)
			}
		}
		dist = next_dist
	}
	dist
end

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

	node_idx = {}
	out_neighbour = Hash.new(0)
	in_neighbour = Hash.new(0)

	cross_points = (1..n).map { gets.chomp.split(?-) }
	puts node_num = cross_points.flatten.uniq.size
	graph = (1..node_num).map { [Float::INFINITY] * node_num }
	
	cross_points.each do |s, t|
		i = (node_idx[s] ||= node_idx.size)
		j = (node_idx[t] ||= node_idx.size)
		out_neighbour[i] |= (1 << j)
		in_neighbour[j] |= (1 << i)
		graph[i][j] = 1
	end

	(0..node_num-1).each do |i|
		neighbours = (0..node_num-1).select{|x| out_neighbour[i][x] == 1}
		neighbours.combination(2) do |j, k|
			next if in_neighbour[j] & out_neighbour[k] > 0
			next if in_neighbour[k] & out_neighbour[j] > 0
			graph[j][k] = 2
			graph[k][j] = 2
		end
		neighbours = (0..node_num-1).select{|x| in_neighbour[i][x] == 1}
		neighbours.combination(2) do |j, k|
			next if in_neighbour[j] & out_neighbour[k] > 0
			next if in_neighbour[k] & out_neighbour[j] > 0
			graph[j][k] = 2
			graph[k][j] = 2
		end
	end

	dist = warshall_floyd(graph)
    
	m = gets.to_i
	m.times do
		s, t = gets.chomp.split(?-)
		i = node_idx[s]
		j = node_idx[t]
		if !i || !j
			puts 'NO'
			next
		end
		
		d = dist[i][j]
		if d == Float::INFINITY || d.even?
			puts 'NO'
		else
			puts 'YES'
		end
	end
end