Problem 1
The Booga
company manufactures finest quality of optical fibres. A single optical fibre
strand is a short glass-like string coated with coloured
cladding. Each single strand can carry light of a single color, which is one of
Violet, Indigo, Blue, Green, Yellow,
An optical device of certain kind has one incoming pipe and one outgoing pipe. You are given n such devices, whose incoming and outgoing pipes' colors are specified. Two devices can be coupled together if the outgoing pipe of one can be merged with the incoming pipe of the other. Two optical pipes can be merged if an only if they contain the same set of colors of strands (not necessarily same numbers). You have to find out whether it is possible to couple all the n devices to form a series combination of the devices. Thus there will be (n-1) merging of optical pipes.
Input:
There will be several test cases. Each test-case starts with the number of optical-pipes n (2 <= n <= 1000). Then n lines follow, each containing the description of a single optical-pipe. Each optical-pipe is specified by the two words (of length at most 80), denoting the color-set at its incoming ant outgoing end respectively. A value 0 (zero) for n indicates the end of input. This should not be processed. Each case is separated by a blank line.
Output:
For each test case print "Yes" if it is possible to combine all the n devices in a linear sequence, one coupled with its neighbour in order. Otherwise print "No".
Sample input:
3
# gy
ygg
w
vibgyor
bgg
2
rg bg
b rb
0
Sample output:
Yes
No