TEMPLE01 - TEMPLE_RUN

no tags 

The city of Forum Boarium is full of temples. Unlike other cities the temples are built in a circular fashion in Forum Boarium and each of these temples consists of exactly three floors. These floors are assigned a label, which is nothing but an English Alphabet.The speciality of the Circular arrangement of temples is that, standing in any temple, we could see all other temples in the city. But over the years, all the temples have lost their sacredness except one.

Hercules arrives to this city, and wishes to visit the temple which is still sacred. An old wicked friend of Hercules leads him to the ground floor of the temple, T1But knowing the nature of his wicked friend, Hercules consults the old - aged people over there and finds the temple which still has its divine power (T2). In order to reach T2 there areĀ  only two possible moves Hercules could do:

  • Either shift between the floors of the same temple, or
  • Jump between the same indexed floors (having same labels) of two different temples. Some old ritual also says that, the labels of the corresponding floors other than the chosen one for jumping, must differ.

Input

The first line contains an integer t (1 <= t <= 10), the number of scenarios, t scenarios follow.

The first line of each scenario contains an integer N (2 <= N <= 3000), the number of temples. (The temples are numbered from 1 to N).

Each of the following N lines contains the labels of the floors: a1, a2, a3 (from bottom to top).

The next line contains two integers: T1 (1 <= T1 <= N), the index of the temple he is currently in and T2 (1 <= T2 <= N), the index of the temple which is still divine.

Output

For each scenario print a single line - "Yes.", if the sacred temple could be reached, or otherwise "No.".

Example

Input:
1
3
a f r
a t p
x t m
1 3
Output: Yes.

hide comments
Karsten Ari Agathon: 2016-10-31 06:52:55

there is additional whitespace from input, got WA using getchar. Use %s to scan labels.

hodobox: 2016-07-01 11:17:18

Clarification on second type of move (after AC):
Hercules can jump from temple A to temple B from some chosen floor X, if and only if the labels of floor X, and only for the chosen floor X, are same for temples A and B.
example:
a b c
a c b
The first floor satisfies the condition, so Hercules can jump.
a b c
a b x
Since both the first and second floor have equal labels, Hercules can not jump.

Last edit: 2016-07-01 11:20:37
Fendy: 2015-10-13 16:38:15

Can you elaborate the condition for the second type of move? it's a bit confusing :/


Added by:Mohan K
Date:2014-11-24
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM32-GCC ASM64 MAWK BC C-CLANG NCSHARP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY JULIA KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYPY3 R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET
Resource:Own