Chef has just found a recipe book, where every dish consists of exactly four ingredients.
He is going to choose some two dishes and prepare them for dinner.
Of course, he likes diversity and wants to know whether the two dishes are similar.
Two dishes are called similar if at least half of their ingredients are the same.
In other words, at least two of four ingredients of the first dish should also be present in the second dish.
The order of ingredients doesn't matter.
Your task is to examine T pairs of dishes.
For each pair, check if the two dishes are similar and print "similar" or "dissimilar" accordingly.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of each test case contains four distinct strings, denoting ingredients needed for the first dish.
Each ingredient is represented by a string of length between 2 and 10 inclusive, consisting of lowercase English letters.

The second line of each test case describes the second dish in the same format.

-----Output-----
For each test case, output a single line containing the answer — "similar" if at least half of the ingredients are same, and "dissimilar" otherwise (without the quotes).

-----Constraints-----
- 1 ≤ T ≤ 200
- The length of each string will be between 2 and 10 inclusive.

-----Example-----
Input:
5
eggs sugar flour salt
sugar eggs milk flour
aa ab ac ad
ac ad ae af
cookies sugar grass lemon
lemon meat chili wood
one two three four
one two three four
gibberish jibberish lalalalala popopopopo
jibberisz gibberisz popopopopu lalalalalu

Output:
similar
similar
dissimilar
similar
dissimilar

-----Explanation-----
Test case 1. The first dish consists of ingredients: eggs, sugar, flour, salt, while the second dish consists of: sugar, eggs, milk, flour. Three of four ingredients are present in both dishes (eggs, sugar, flour) so the two dishes are similar.
Test case 2. This example shows that strings in the input don't necessarily represent real food.
The answer is again "similar", because two ingredients are present in both dishes ("ac" and "ad").
Test case 3. The only common ingredient is lemon, so the answer is "dissimilar".
Remember that at least two ingredients should be present in both dishes.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
for i in range(int(input())):
	a = list(map(str, input().split()))
	a.sort()
	b = list(map(str, input().split()))
	b.sort()
	c = 0
	for j in range(4):
		if a[j] in b:
			c += 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	s = input().split()
	print('similar' if len(set(s).intersection(input().split())) >= len(s) / 2 else 'dissimilar')


for _ in range(int(input())):
	first = input().split()
	second = input().split()
	count = 0
	for i in first:
		if i in second:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')


T = int(input())
for _ in range(T):
	s1 = input().split()
	s2 = input().split()
	count = 0
	for i in s1:
		if i in s2:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	s1 = input().split(' ')
	s2 = input().split(' ')
	c = 0
	for i in s1:
		if i in s2:
			c += 1
	if c >= len(s1) // 2:
		print('similar')
	else:
		print('dissimilar')


n = int(input())
for i in range(0, n):
	l1 = list(input().split())
	l2 = list(input().split())
	l3 = []
	for item in l1:
		if item in l2:
			l3.append(item)
	if len(l3) >= 2:
		print('similar')
	else:
		print('dissimilar')


n = int(input())
l = []
for i in range(0, n):
	s1 = list(map(str, input().split()))
	s2 = list(map(str, input().split()))
	count = 0
	for j in range(len(s1)):
		if s1[j] in s2:
			count += 1
	total = len(s1) / 2
	if count >= total:
		l.append('similar')
	else:
		l.append('dissimilar')
for i in l:
	print(i)


for _ in range(int(input())):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	c = 0
	for i in a:
		if i in b:
			c += 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for _ in range(t):
	a = set(input().split())
	b = set(input().split())
	if len(a.intersection(b)) >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for tc in range(t):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	c = []
	for j in a:
		if j in b:
			c.append(j)
	if len(set(c)) < 2:
		print('dissimilar')
	else:
		print('similar')


t = int(input())
for i in range(t):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	c = sorted(a)
	d = sorted(b)
	p = 0
	for i in range(len(c)):
		for j in range(len(c)):
			if c[i] == d[j]:
				p = p + 1
	if p >= 2:
		print('similar')
	else:
		print('dissimilar')


import sys
for _ in range(int(sys.stdin.readline())):
	s = sys.stdin.readline().split()
	sys.stdout.write('similar\n' if len(set(s).intersection(sys.stdin.readline().split())) >= len(s) / 2 else 'dissimilar\n')


for _ in range(int(input())):
	A = list(map(str, input().split()))
	B = list(map(str, input().split()))
	r = 0
	for i in A:
		if i in B:
			r += 1
	if r >= 2:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	lia = list(input().split())
	lib = list(input().split())
	count = 0
	for i in lia:
		if i in lib:
			count += 1
	print('similar' if count >= len(lia) // 2 else 'dissimilar')


for i in range(int(input())):
	a = set(list(input().split()))
	b = set(list(input().split()))
	c = a.intersection(b)
	if len(c) > 1:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	ingre = set()
	dish1 = set(input().split())
	dish2 = set(input().split())
	if len(dish1 & dish2) >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
i = 0
while i < t:
	a = []
	a = input().split()
	b = []
	b = input().split()
	j = 0
	c = 0
	while j < 4:
		if a[j] in b:
			c += 1
		j += 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')
	i += 1


for i in range(int(input())):
	a = input().split()
	b = input().split()
	k = 0
	for i in range(4):
		for j in range(4):
			if a[i] == b[j]:
				k = k + 1
	if k >= 2:
		print('similar')
	else:
		print('dissimilar')


for __ in range(int(input())):
	d1 = [i for i in input().split(' ')]
	d2 = [i for i in input().split(' ')]
	s1 = set(d1)
	s2 = set(d2)
	z = s1.intersection(s2)
	x = len(s1) // 2
	y = len(z)
	if y >= x:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	A = input().split()
	B = input().split()
	c = 0
	for j in A:
		if j in B:
			c += 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
while t > 0:
	str_1 = set(input().split())
	str_2 = set(input().split())
	if len(str_1.intersection(str_2)) >= 2:
		print('similar')
	else:
		print('dissimilar')
	t -= 1


t = int(input())
for i in range(t):
	l = list(input().split())
	m = list(input().split())
	c = 0
	for i in l:
		if i in m:
			c += 1
	if c >= len(l) // 2:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	T = [i for i in input().split()]
	P = len([i for i in input().split() if i in T])
	if P >= 2:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	dish1 = list(input().split())
	dish2 = list(input().split())
	count = 0
	for i in dish1:
		if i in dish2:
			count += 1
			if count == 2:
				print('similar')
	if count < 2:
		print('dissimilar')


for _ in range(int(input())):
	s1 = [x for x in input().split()]
	s2 = [x for x in input().split()]
	if len(set.intersection(set(s1), set(s2))) >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for i in range(t):
	a = input().split()
	b = input().split()
	c = 0
	for i in a:
		if i in b:
			c = c + 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	x = round(len(a) / 2)
	c = 0
	for i in range(len(a)):
		if a[i] in b:
			c += 1
			if c == x:
				break
	if c == x:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for it in range(t):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	c = 0
	for item in a:
		if item in b:
			c += 1
	print('similar') if c > 1 else print('dissimilar')


t = int(input())
for ts in range(t):
	n = set(input().split())
	m = set(input().split())
	if len(n.intersection(m)) >= 2:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	d1 = list(map(str, input().split()))
	d2 = list(map(str, input().split()))
	count = 0
	for i in d2:
		if i in d1:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')


goals = int(input())
for distractions in range(goals):
	life = list(map(str, input().split()))
	aim = list(map(str, input().split()))
	wife = 0
	for stress in life:
		if stress in aim:
			wife += 1
	if wife >= len(life) // 2:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	d = dict()
	a = list(input().split())
	b = list(input().split())
	for j in a:
		if j in d.keys():
			d[j] += 1
		else:
			d[j] = 1
	for j in b:
		if j in d.keys():
			d[j] += 1
		else:
			d[j] = 1
	ic = 0
	for j in d.keys():
		if d.get(j) >= 2:
			ic += 1
	if ic >= 2:
		print('similar')
	else:
		print('dissimilar')


T = int(input())
for i in range(T):
	dish1 = list(input().split())
	dish2 = list(input().split())
	similar = 0
	for i in dish1:
		for j in dish2:
			if i == j:
				similar = similar + 1
	if similar >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
while t:
	a1 = list(map(str, input().split()))[:4]
	a2 = list(map(str, input().split()))[:4]
	cnt = 0
	for i in range(4):
		if a1[i] in a2:
			cnt += 1
		else:
			continue
	if cnt >= 2:
		print('similar')
	else:
		print('dissimilar')
	t -= 1


n = int(input())
for i in range(n):
	(a, b, c, d) = input().split()
	(w, x, y, z) = input().split()
	m = []
	n = []
	m.append(a)
	m.append(b)
	m.append(c)
	m.append(d)
	n.append(w)
	n.append(x)
	n.append(y)
	n.append(z)
	c = 0
	for i in m:
		if i in n:
			c = c + 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
while t > 0:
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	x = len(a) // 2
	c = 0
	for i in a:
		if i in b:
			c = c + 1
	if c >= x:
		print('similar')
	else:
		print('dissimilar')
	t = t - 1


for i in range(int(input())):
	l1 = list(input().split())
	l2 = list(input().split())
	count = 0
	for j in l1:
		if j in l2:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for i in range(t):
	d1 = list(map(str, input().split()))
	d2 = list(map(str, input().split()))
	c = 0
	for x in d1:
		if x in d2:
			c += 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


T = int(input())
for i in range(T):
	l1 = list(map(str, input().split()))
	l2 = list(map(str, input().split()))
	c = 0
	for i in l2:
		if i in l1:
			c += 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	fir = set(map(str, input().split()))
	sec = set(map(str, input().split()))
	a = fir.intersection(sec)
	if len(a) >= 2:
		print('similar')
	else:
		print('dissimilar')


for t in range(int(input())):
	dish1 = list(map(str, input().split(' ')))
	dish2 = list(map(str, input().split(' ')))
	count = 0
	for ingredient in dish1:
		if ingredient in dish2:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	s = input().split()
	e = input().split()
	c = 0
	for i in s:
		if i in e:
			c += 1
	if c >= len(s) // 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for i in range(t):
	a = list(input().split())
	b = list(input().split())
	count = 0
	for i in range(len(a)):
		for j in range(len(b)):
			if a[i] == b[j]:
				count = count + 1
	if count > 1:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	k = 0
	for i in range(len(a)):
		if a[i] in b:
			k += 1
	if k > 1:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for _ in range(t):
	dish_1 = list(map(str, input().split()))
	dish_2 = list(map(str, input().split()))
	count = 0
	for i in range(4):
		if dish_1[i] in dish_2:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
while t != 0:
	a = list(input().split())
	b = list(input().split())
	c = 0
	for x in a:
		if x in b:
			c += 1
		if c > 1:
			break
	if c > 1:
		print('similar')
	else:
		print('dissimilar')
	t -= 1


t = int(input())

def do():
	a = [d for d in input().split()]
	b = [e for e in input().split()]
	if len(set(a) & set(b)) >= 2:
		print('similar')
	else:
		print('dissimilar')
	return
for i in range(t):
	do()


for t in range(int(input())):
	first = input().split(' ')
	second = input().split(' ')
	cnt = 0
	for i in first:
		if i in second:
			cnt += 1
	if cnt > 1:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	l = []
	l = input().split()
	k = []
	k = input().split()
	k.sort()
	l.sort()
	c = 0
	for j in l:
		for m in k:
			if j == m:
				c += 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


for t in range(int(input())):
	s1 = list(map(str, input().split(' ')))
	s2 = list(map(str, input().split(' ')))
	c = 0
	for i in s1:
		if i in s2:
			c += 1
	if c >= 2:
		print('similar')
	else:
		print('dissimilar')


from collections import Counter
for _ in range(int(input())):
	l = list(map(str, input().split())) + list(map(str, input().split()))
	l = Counter(l)
	if list(l.values()).count(1) > 4:
		print('dissimilar')
	else:
		print('similar')


t = int(input())
while t:
	A = list(map(str, input().split()))
	B = list(map(str, input().split()))
	s = 0
	for i in A:
		if i in B:
			s = s + 1
	if s >= 2:
		print('similar')
	else:
		print('dissimilar')
	t = t - 1


def dish(a, b):
	a = a.split()
	b = b.split()
	(i, j) = (0, 0)
	c = 0
	while i < len(a):
		if a[i] == b[j]:
			c = c + 1
		j = j + 1
		if c >= 2:
			return 'similar'
		if j == len(b):
			i += 1
			j = 0
	else:
		return 'dissimilar'
for i in range(int(input())):
	s1 = input()
	s2 = input()
	print(dish(s1, s2))


import sys
for _ in range(int(sys.stdin.readline())):
	s = list(map(str, sys.stdin.readline().split()))
	x = list(map(str, sys.stdin.readline().split()))
	sys.stdout.write('similar\n' if len(set(s).intersection(x)) >= len(s) / 2 else 'dissimilar\n')


for O in range(int(input())):
	l1 = input().split()
	l2 = input().split()
	s1 = set(l1)
	s2 = set(l2)
	s = set()
	s = s1.intersection(s2)
	if len(s) >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
while t > 0:
	s = input()
	l1 = list(s.split(' '))
	s = input()
	l2 = list(s.split(' '))
	l = len(l1)
	l = l // 2
	c = fl = 0
	for i in range(0, len(l1)):
		if l1[i] in l2:
			c += 1
		if c == 2:
			fl = 1
			break
	if fl == 1:
		print('similar')
	else:
		print('dissimilar')
	t -= 1


for _ in range(int(input())):
	f = input().split(' ')
	s = input().split(' ')
	c = 0
	for x in f:
		if x in s:
			c += 1
	if c > 1:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	v = list(map(str, input().split()))
	x = list(map(str, input().split()))
	v.sort()
	x.sort()
	count = 0
	for i in v:
		if i in x:
			count += 1
	if count >= len(v) // 2:
		print('similar')
	else:
		print('dissimilar')


for nt in range(int(input())):
	ct = 0
	(st1, st2) = (list(map(str, input().split())), list(map(str, input().split())))
	for i in st2:
		if i in st1:
			ct += 1
	print('similar') if ct >= int(len(st1) / 2) else print('dissimilar')


for _ in range(int(input())):
	a = set(input().split())
	c = 0
	for i in input().split():
		c += int(i in a)
	if c > 1:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for _ in range(t):
	f = list(input().split())
	s = list(input().split())
	f_set = set(f)
	s_set = set(s)
	inter = f_set.intersection(s_set)
	if len(inter) >= 2:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	a1 = list(map(str, input().split()))[:4]
	a2 = list(map(str, input().split()))[:4]
	cnt = 0
	for i in range(4):
		if a1[i] in a2:
			cnt += 1
	if cnt >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
while t:
	l1 = list(input().split())
	l2 = list(input().split())
	count = 0
	for i in l1:
		if i in l2:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')
	t -= 1


for _ in range(int(input())):
	m = [i for i in input().split()]
	p = len([i for i in input().split() if i in m])
	print('similar' if p >= 2 else 'dissimilar')


for _ in range(int(input())):
	m = set(map(str, input().split()))
	n = set(map(str, input().split()))
	v = 0
	for i in m:
		if i in n:
			v += 1
	if v >= 2:
		print('similar')
	else:
		print('dissimilar')


T = int(input())
for i in range(T):
	d1 = list(input().split())
	d2 = list(input().split())
	si = 0
	for i in d1:
		for j in d2:
			if i == j:
				si = si + 1
	if si >= 2:
		print('similar')
	else:
		print('dissimilar')


for _ in range(int(input())):
	r1 = list(map(str, input().split()))
	r2 = list(map(str, input().split()))
	count = 0
	for i in r1:
		if i in r2:
			count += 1
			if count == 2:
				break
	if count == 2:
		print('similar')
	else:
		print('dissimilar')


for tc in range(int(input())):
	d = list(input().split())
	e = list(input().split())
	cnt = 0
	for s in d:
		if s in e:
			cnt += 1
	if cnt >= len(d) // 2:
		print('similar')
	else:
		print('dissimilar')


x = int(input())
for i in range(x):
	y = list(map(str, input().split()))[:4]
	z = list(map(str, input().split()))[:4]
	m = 0
	for j in range(4):
		for k in range(4):
			if y[j] == z[k]:
				m += 1
	if m >= 2:
		print('similar')
	else:
		print('dissimilar')


for i in range(int(input())):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	an = 0
	for j in a:
		if j in b:
			an += 1
	if an > 1:
		print('similar')
	else:
		print('dissimilar')


jj = int(input())
for fo in range(jj):
	a = list(input().split())
	b = list(input().split())
	o = 0
	for i in a:
		if i in b:
			o += 1
			if o == 2:
				print('similar')
				break
	else:
		print('dissimilar')


T = int(input())
for _ in range(T):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	count = 0
	for item in a:
		if item in b:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')


t = int(input())
for i in range(t):
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	count = 0
	for j in range(4):
		if b.count(a[j]) == 1:
			count += 1
	if count >= 2:
		print('similar')
	else:
		print('dissimilar')