Chef becomes Poet
Chef’s girlfriend is not talking to him because Chef has forgotten her birthday. Their relationship is on the verge of breakup and Chef has got one last chance to save his relationship. So Chef is making a poem for his girlfriend so that she becomes happy and starts talking with him again. But, this is not easy and only random words are coming to the Chef’s mind. Chef is not able to rhyme these words properly. You have to help Chef so that his relationship is saved and he is not “single” again.
Chef has N number of strings, your task is to tell whether these strings can be rhymed or not. The criteria for rhyming is that the last character of the previous string should be same as the first character of the next string. If such a pattern exists then the output should be YES else NO.
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The next line contains an integer N, where N is the number of strings.
N lines follow each containing a string S.
If it is possible to obtain such a pattern then print YES else print NO.
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 1000
- 1 ≤ S ≤ 100
Input: 2 3 chef soccer forgets 4 drawing vertex geoboard directed Output: YES NO
Example For test case 1, there exists pattern arrangement “chef forgets soccer”.
|Tags||akashdeep_uiet, medium, strings|
|Time Limit:||0.5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions