After escaping from
's basement, you finally breathe fresh air! However, it's not so easy... you pick up your phone to tell everyone you're okay, but as you fiddle around with the computer's settings, you notice someone extra in the list of administrators... Wait a minute!Who's this account called "Amon" on the computer? And who does it belong do? You decide to try and sign into the account. The password is "ReadyToProgram"... of course it is. You scour the computer's files and come across a text file named "CALL_HISTORY_DO_NOT_TOUCH". Looking for any evidence that could solve your case, you click the file. Inside is a list of pairs of phone numbers. At first, you're not sure what it means, but after test-calling
, who obviously didn't pick up since it's 6pm in the afternoon (Why would he be awake?), your call gets added to the ever-increasing list. It seems had secretly downloaded an app on everyones' phones that lets her track phone calls!Any one of those numbers in the text file could be Amon. As someone who doesn't pick up calls from unknown numbers, you assume that everyone else is the same, and will only pick up phone calls of phone numbers they recognize. You decide to scroll through the file and find out anyone who has called these phone numbers, to see if you can use these personal connections to find who Amon really is. The file contains lines, and you have
questions that you want to ask yourself. Those questions are all the same: "Are the people with phone number
and phone number
connected in any way?" Two people are considered "connected" if there is a chain of phone calls that lead from phone number
to phone number
.
Constraints
are 10-digit phone numbers.
Input Specifications
The first line will contain a single integer, .
The next lines will contain two integers,
and
, indicating
called
.
The next line will contain a single integer, , the number of queries.
The next lines will contain two integers,
and
, asking if
and
are connected.
Output Specifications
For each query, output on a separate line, Y
if the two phone numbers are connected, or N
otherwise.
Sample Input
5
4163764972 9053985763
6472983645 4163764972
6478823647 4371234567
4371234567 6472983645
9053985763 4371234567
1
4371234567 9053985763
Sample Output
Y
Explanation for Sample Output
4371234567
called 6472983645
, who called 4163764972
, who called 9053985763
. Notice that there are other possible connections to reach 9053985763
from 4371234567
.
Comments