New Year Trip

0

0 votes
Easy
Problem

On this new year occasion our college is deciding to go for a trip to Sydney harbour Australia .
There hotels are in form of matrix of r rows and c cols . Every two rooms sharing a common wall have a window through the wall to communicate during the stay

Now there are n where n = rc students , These students are from d departments , department students want to communicate with each other during their stay . Two students can communicate during the stay if there is a window between their room or if there are few same department friends in way of same department through whom they can send message .
Like if A share window with B , B share window with C , C share window with D . then A can talk to D if all of them are from same department .
A hotel is good if all the students of same department can get a room in such a way that they can communicate with each other .
Udit was given the responsibility to check whether the hotel is good or not . He devised an algorithm to check it out . Due to some reasons Udit is busy somewhere else and we are not in touch with him . You are given the task to check if the hotel is good or not . Now a hotel is selected with rc rooms and there are rc students we have to check if this hotel is good or not.

INPUT
first line of input will contain single integer t as number of test cases 1<=t<=100
first line of test case will contain three integers r c d as number of rows colns and departments respectively
second line of test case will contain n = rc integers di each integer will denote department number of ith student . department numbers are from 1 to d.

OUTPUT
for each test case output yes or no in separate line .
yes means the hotel is good , no means hotel is bad.

CONSTRAINTS
1<=t<=100
1<=r,c<=100
1<=d<=100
1<=di<=d
n=r*c
n<=1000

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

you can give rooms as

1 1 1 2 3
1 1 1 2 3

all of the students of same department can communicate with each other easily so the hotel is good and output is yes

Editor Image

?