Background
On its trip, a train has to pass a lot of points (American English: switches) and signals. The train抯 track depends on the status of points and signals. The responsible operator on the signal box does not handle them separately, but tells the signal box the start and destination signal of the train抯 journey. The box then determines the correct status of points and signals and brings them into the right position.
The first line contains the number of scenarios.
In the first line of the input for every scenario, you are given two signal identifiers for the departure and the destination, separated by a single blank. The following line contains the number n of elements (points and signals) in the track plan. You can assume 1<=n<=200 and that each element has a unique identifier of at most 20 alphanumeric characters. The identifier "XXX" is given to track ends.
There are signal and point elements, given in the following format:
Points are specified by a line "W I F M P" where W stands for "Weiche" (German for point), I is the identifier of the point, F identifies the front element of the point, and M and P give the identifiers of the back elements of the point depending on whether it is in minus or plus position.
Signals are specified by a line "S I F B" where S stands for "Signal" (German for signal), I is the identifier of the signal, and F and B give the identifiers of the front and back elements of the signal.
The direction for which the signal is valid is from front to back.
The following line contains the number p, 0<=p<=100, of path selection rules, followed by another p lines of the rules themselves. A rule is of the form "FW X Y Z" where FW is the identifier of "Fahrstrabenwahl-Regel" (German for path selection rule), X, Y and Z are the elements of the rule as explained above.
The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1.
For every scenario print out the elements on the path from departure to destination in the order they are passed by the train. However, print the signals first, followed by the points. Every element of the path must be on a line by itself. Elements of the path are signal and point identifiers (the first and the last signal identifiers must also be printed). For every point you should also give the correct position of the point as either + or - on the same line, separated from the point identifier by a single blank. If there is no possible path, print "NOT POSSIBLE".
Terminate each scenario by a blank line.
4 A AC 14 S AB A XXX S A AB W1 W W1 A W2 P3 W W2 W1 P1 P2 S P1 N1 W2 S N1 P1 W11 W W11 F N1 W12 S F AC W11 S AC F XXX S P2 N2 W2 S N2 P2 W12 W W12 W11 N3 N2 S P3 N3 W1 S N3 P3 W12 2 FW W1 W11 + FW W11 W1 - S1 S2 2 S S1 S2 XXX S S2 S1 XXX 0 S1 S4 6 S S1 XXX W1 S S2 W1 XXX S S3 XXX W2 S S4 W2 XXX W W1 S1 S2 W2 W W2 S4 W1 S3 0 S1 S2 8 S S1 XXX W1 S S2 W4 XXX S S3 W1 W2 S S4 W3 W4 W W1 S1 W2 S3 W W2 W3 W1 S3 W W3 W2 W4 S4 W W4 S2 W3 S4 1 FW W1 W2 +
Scenario #1: A N3 AC W1 + W12 - W11 + Scenario #2: NOT POSSIBLE Scenario #3: S1 S4 W1 + W2 - Scenario #4: S1 S3 S2 W1 + W2 + W3 - W4 -