Attending Events

0

0 votes
Problem

As we know confluence is going on in our college and Deepak is also very excited to attend all the events. But he is a crazy guy, he has decided that either he will attend all the events or he will not attend even a single event. Also, he will attend all the events if and only if there is atleast one arrangement possible of names of events such that name of ith event starts with the character with which (i-1)th event has ended. For example event "encoder" must be followed by event "rishti". So, the task is to write a program that will read names of n events and determine whether it is possible to have any such sequence of events which follow the given rule.

INPUT: First line contains number of test cases t.For each test case we have number of events n and following n lines contains names of these events. Each event names contains atleast 2 and atmost 100 charachters all being in lower case i.e. from 'a' to 'z' only. t <= 100 n <= 100000

OUTPUT: Your program must determine if Deepak can attend the events or not. If he can attend the events then output must be "YES" else it should be "NO" without double quotes.For each test case output your answer "YES" or "NO" in separate lines.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Test Case 1: Sequence :- encoder -> rishti -> impact -> target

Editor Image

?