# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

# Directed Rectangle

By sakibalamin · Limits 1s, 512 MB

Sami has just finished his assignments, to relax, he wants to play games. Since he’s banned from PUBG (please don’t cheat), he found an interesting game “Directed Rectangle”, in which he is given a rectangle similar to the figure below.

Each edge of the rectangle is directed (notice the arrows). If there is an arrow from X to Y, it means the player can use this edge to go from X to Y, but not from Y to X using the same edge. In general, a player can only travel to points using the arrows.

Sami gives you the descriptions about the four edges in the form of “X -> Y”, meaning that there is a directed edge from X to Y. And “X <- Y” means the opposite direction. (X and Y are characters from ‘A’ to ‘D’, describing the corner points.)

He now wants to ask you some queries about the rectangle. You are given an integer Q denoting the number of queries. In each query, you are given two characters X and Y.

For each query, you have to print “YES” if the player can start at “X” and travel to “Y” using the directed edges, else print “NO”.

Note: You must use atleast one directed edge to travel from “X” to “Y”.

## Input

The first four lines of each test case will describe each of the four edges of the rectangle. The positions of A, B, C, and D will be the same as in the figure above. If there is a directed edge from A to B, it will be given like “A -> B”, or “A <- B” if the direction is from B to A. Next there will be an integer Q, the number of queries. Q line follows, each line will contain two characters X and Y. There will at most 50 queries in a test case.

## Output

For each query, you have output one line. If it is possible to go from X to Y output “YES” otherwise “NO” without quotes.

## Samples

InputOutput
```A -> B
B -> C
C <- D
D <- A
4
A D
A C
D A
B B
```
```YES
YES
NO
NO
```
InputOutput
```A -> B
B -> C
C -> D
D -> A
4
A D
A C
D A
B B
```
```YES
YES
YES
YES
```

• ### Statistics

89% Solution Ratio

bmqubeEarliest, 1M ago

bmqubeFastest, 0.0s

bmqubeLightest, 131 kB 