There is a social networking site in which users can send friend request to other users and can also follow. Let's say if user A sends friend request to B and if B accepts then A and B are called as friends and if B rejects the request then just A will follow B.
You will be given the status of the requests sent all over the network. And given two users you have to print “YES”(without quotes) if they can are connected directly as friends/followers or via friends of friends/friends of friends of friends or so on, and “NO”(without quotes) if they are not.
The term connected means if A is a friend of B and B is a friend of C, then A and C are connected. Also friends of C can be called as connected to A and B.
If A follows B then also we can say that A and B are connected. But here if A and C are friends then B and C are not connected.
The users will be identified by their ids.
Note: Friends are not followers.
Input:
First line will contain the number of users n in the network and total friend requests sent f.
Thus the users will have ids from 1 to n.
Next f lines will contain the status of requests in the form of either “A id1 id2” or “R id1 id2”.
The notation “A id1 id2” denotes that the user with id2 accepted the request sent by the user with id1 and thus both are now friends. And “R id1 id2” denotes that the user with id2 rejected the request sent by the user with id1 and thus he follows the other(user id1 follows user id2).
Next line will contain q denoting number of queries.
Next q lines will contain two space separated integers,id of 2 users for which you have to find whether
thet are connected or not.
Output:
Output “YES” or “NO” depending on the query on new line.
Constraints:
2 <= n <= 105
1 <= f <= 105
1 <= q <= 103