For this problem, we'll be given a sequence of input lines, each of which is either an assertion of a new found equivalence or a question as to whether two names are equivalent. For each assertion, make note of it for future reference. For each question, answer based on the data so far, i.e. on the information from the preceeding lines only. Thus a given question might get the answer "no" early on, but later after new equivalence discoveries the same question may get the answer "yes". Needless to say, if "A" is equivalent to "B" and "B" is equivalent to "C" then "A" is equivalent to "C".
There is a lot of stuff out there in the heavens. The list of assertions and questions may be very long, like a hundred thousand.
same! "Vega" "Lyra-1"or
same? "andromeda galaxy" "andromeda nebula"
same! "Ursa Major" "Big Dipper" same? "Great Bear" "Ursa Major" same! "Great Bear" "Big Dipper" same? "Great Bear" "Ursa Major" same? "Big Dipper" "Banana boat" same? "A" "A"
same? "Great Bear" "Ursa Major" no same? "Great Bear" "Ursa Major" yes same? "Big Dipper" "Banana boat" no same? "A" "A" yes