Social networks

A long time back (earlier this week, but seems that way) when York declared a snow day, a diligent York student started thinking about social networks and how they suggest possible candidates for friends. The obvious way is by using common friends, but that does not always work (it may suggest that you connect to your friends' parents!). So the student thinks about using shared interests. Here is his idea. Users can "like" other users' comments/status updates/pictures/interests etc. He decides to abstract away some details in the following way. Think of users as nodes. When user A likes one or more aspects of user B's page, we add a directed edge from A to B. Then if user A and C both have directed edges to user B, then it is plausible that users A, C could be friends.

The student thinks of other schemes to improve on this (including perhaps checking users' ages) but York announces that the snow day must be made up and this throws the student into deep depression. Your job is to implement the student's idea.

Input
You will be given several instances of the problem. Each instance starts with integers n,m on the first line (separated by a blank). The number of nodes is n (numbered 1..n) and the number of edges is m. For this problem, n,m < 100,000.

This is followed by m lines each with a pair of node id's a,b (separated by a blank) that specifies a single directed edge from node a to node b. This is followed by one or more lines with node pairs (separated by a blank) for which you must produce output. The last line in this list is indicated by 0 0; no output should be produced for this line. After the last instance there is a line containing 0 0 that denotes end of input; this line is used only as an end of input indicator and should not be otherwise processed.

Output
For each instance, print the instance number, starting from 1. Then for each given node pair (a,b) the set of nodes c (in increasing order) that satisfy the condition that directed edges (a,c), (b,c) are in the graph. See the sample output for the precise format.

Sample input
3 3
1 2
1 3
2 3
1 2
2 3
0 0
0 0

Sample output
Instance 1
Common neighbours of nodes 1,2:
3
Common neighbours of nodes 2,3: