Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discovers a new relation between two words.

He know that if two words have a relation between them, then each of them has relations with the words that has relations with the other. For example, if like means love and love is the opposite of hate, then like is also the opposite of hate. One more example: if love is the opposite of hate and hate is the opposite of like, then love means like, and so on.

Sometimes Mahmoud discovers a wrong relation. A wrong relation is a relation that makes two words equal and opposite at the same time. For example if he knows that love means like and like is the opposite of hate, and then he figures out that hate means like, the last relation is absolutely wrong because it makes hate and like opposite and have the same meaning at the same time.

After Mahmoud figured out many relations, he was worried that some of them were wrong so that they will make other relations also wrong, so he decided to tell every relation he figured out to his coder friend Ehab and for every relation he wanted to know is it correct or wrong, basing on the previously discovered relations. If it is wrong he ignores it, and doesn't check with following relations.

After adding all relations, Mahmoud asked Ehab about relations between some words based on the information he had given to him. Ehab is busy making a Codeforces round so he asked you for help.


-----Input-----

The first line of input contains three integers n, m and q (2 ≤ n ≤ 10^5, 1 ≤ m, q ≤ 10^5) where n is the number of words in the dictionary, m is the number of relations Mahmoud figured out and q is the number of questions Mahmoud asked after telling all relations.

The second line contains n distinct words a_1, a_2, ..., a_{n} consisting of small English letters with length not exceeding 20, which are the words in the dictionary.

Then m lines follow, each of them contains an integer t (1 ≤ t ≤ 2) followed by two different words x_{i} and y_{i} which has appeared in the dictionary words. If t = 1, that means x_{i} has a synonymy relation with y_{i}, otherwise x_{i} has an antonymy relation with y_{i}.

Then q lines follow, each of them contains two different words which has appeared in the dictionary. That are the pairs of words Mahmoud wants to know the relation between basing on the relations he had discovered.

All words in input contain only lowercase English letters and their lengths don't exceed 20 characters. In all relations and in all questions the two words are different.


-----Output-----

First, print m lines, one per each relation. If some relation is wrong (makes two words opposite and have the same meaning at the same time) you should print "NO" (without quotes) and ignore it, otherwise print "YES" (without quotes).

After that print q lines, one per each question. If the two words have the same meaning, output 1. If they are opposites, output 2. If there is no relation between them, output 3.

See the samples for better understanding.


-----Examples-----
Input
3 3 4
hate love like
1 love like
2 love hate
1 hate like
love like
love hate
like hate
hate like

Output
YES
YES
NO
1
2
2
2

Input
8 6 5
hi welcome hello ihateyou goaway dog cat rat
1 hi welcome
1 ihateyou goaway
2 hello ihateyou
2 hi goaway
2 hi hello
1 hi hello
dog cat
dog hi
hi hello
ihateyou goaway
welcome ihateyou

Output
YES
YES
YES
YES
NO
YES
3
3
1
1
2

Source: codeforces | Difficulty: HARD
Tags: Graph algorithms

Graph traversal

Dynamic programming

Spanning trees

Data structures


Solutions:
(n, m, q) = map(int, input().split())
a = input().split()
c = {x: ([x], []) for x in a}
for i in range(m):
	(t, x, y) = input().split()
	if t == '2':
		sign = 1
	else:
		sign = 0
	if c[x][0] is c[y][1 - sign]:
		print('NO')
		continue
	print('YES')
	if c[x][0] is c[y][sign]:
		continue
	(c1, c2) = (c[x], c[y])
	if len(c1[0]) + len(c1[1]) < len(c2[0]) + len(c2[1]):
		(c1, c2) = (c2, c1)
	(s1, a1) = c1
	if sign == 0:
		(s2, a2) = c2
	else:
		(a2, s2) = c2
	s1 += s2
	a1 += a2
	cs = (s1, a1)
	for x in s2:
		c[x] = cs
	ca = (a1, s1)
	for x in a2:
		c[x] = ca
for i in range(q):
	(x, y) = input().split()
	if c[x][0] is c[y][0]:
		print(1)
	elif c[x][0] is c[y][1]:
		print(2)
	else:
		print(3)


f = lambda : input().split()
(n, m, k) = map(int, f())
c = {x: ([x], []) for x in f()}
for i in range(m):
	(t, x, y) = f()
	s = 2 - int(t)
	(cx, cy) = (c[x], c[y])
	if cx[0] is cy[s]:
		print('NO')
		continue
	print('YES')
	if cx[0] is cy[1 - s]:
		continue
	if len(cx[0]) + len(cx[1]) < len(cy[0]) + len(cy[1]):
		(cx, cy) = (cy, cx)
	(ux, vx) = cx
	if s:
		(uy, vy) = cy
	else:
		(vy, uy) = cy
	ux += uy
	vx += vy
	for x in uy:
		c[x] = (ux, vx)
	for x in vy:
		c[x] = (vx, ux)
for i in range(k):
	(x, y) = f()
	print(1 if c[x][0] is c[y][0] else 2 if c[x][0] is c[y][1] else 3)


def get_relation(synonyms, antonyms, word1, word2):
	if word1 not in synonyms or word2 not in synonyms:
		return '3'
	group1 = synonyms[word1]
	group2 = synonyms[word2]
	if group1 == group2:
		return '1'
	if group1 in antonyms and antonyms[group1] == group2:
		return '2'
	return '3'

def unify_synonyms(synonyms, groups, group1, group2):
	min_group = min(group1, group2)
	max_group = max(group1, group2)
	max_synonyms = groups[max_group]
	for synonym in max_synonyms:
		synonyms[synonym] = min_group
	update_groups(groups, min_group, max_synonyms)
	return (min_group, max_group)

def make_synonyms(synonyms, antonyms, groups, group1, group2):
	(min_group1, max_group1) = unify_synonyms(synonyms, groups, group1, group2)
	if group1 in antonyms and group2 in antonyms:
		(min_group2, max_group2) = unify_synonyms(synonyms, groups, antonyms[group1], antonyms[group2])
		del antonyms[min_group1]
		del antonyms[max_group1]
		del antonyms[min_group2]
		del antonyms[max_group2]
		antonyms[min_group1] = min_group2
		antonyms[min_group2] = min_group1
		return min_group1
	if max_group1 in antonyms:
		antonym_group = antonyms[max_group1]
		del antonyms[max_group1]
		antonyms[min_group1] = antonym_group
		antonyms[antonym_group] = min_group1
	return min_group1

def update_groups(groups, group, words):
	if group in groups:
		groups[group].update(words)
	else:
		groups.update({group: set(words)})

def make_relation(synonyms, antonyms, groups, word1, word2, relation, current_group):
	if relation == '1':
		if word1 not in synonyms and word2 not in synonyms:
			current_group += 1
			synonyms[word1] = current_group
			synonyms[word2] = current_group
			update_groups(groups, current_group, [word1, word2])
			return current_group
		if word1 not in synonyms:
			synonyms[word1] = synonyms[word2]
			update_groups(groups, synonyms[word2], [word1])
			return current_group
		if word2 not in synonyms:
			synonyms[word2] = synonyms[word1]
			update_groups(groups, synonyms[word1], [word2])
			return current_group
		group1 = synonyms[word1]
		group2 = synonyms[word2]
		if group1 != group2:
			make_synonyms(synonyms, antonyms, groups, group1, group2)
		return current_group
	if relation == '2':
		if word1 not in synonyms:
			current_group += 1
			group1 = current_group
			synonyms[word1] = group1
			update_groups(groups, group1, [word1])
		else:
			group1 = synonyms[word1]
		if word2 not in synonyms:
			current_group += 1
			group2 = current_group
			synonyms[word2] = group2
			update_groups(groups, group2, [word2])
		else:
			group2 = synonyms[word2]
		if group1 not in antonyms and group2 not in antonyms:
			antonyms[group1] = group2
			antonyms[group2] = group1
			return current_group
		if group1 in antonyms and antonyms[group1] != group2:
			antonym_group = antonyms[group1]
			group2 = make_synonyms(synonyms, antonyms, groups, group2, antonym_group)
		if group2 in antonyms and antonyms[group2] != group1:
			antonym_group = antonyms[group2]
			make_synonyms(synonyms, antonyms, groups, group1, antonym_group)
	return current_group

def make_relations(relation_no):
	synonyms = dict()
	antonyms = dict()
	groups = dict()
	current_group = 0
	for relation in range(relation_no):
		(relation, word1, word2) = input().split()
		current_relation = get_relation(synonyms, antonyms, word1, word2)
		if current_relation == '2' and relation == '1':
			print('NO')
			continue
		if current_relation == '1' and relation == '2':
			print('NO')
			continue
		print('YES')
		current_group = make_relation(synonyms, antonyms, groups, word1, word2, relation, current_group)
	return (synonyms, antonyms)

def answer_questions(question_no, synonyms, antonyms):
	for question in range(question_no):
		(word1, word2) = input().split()
		print(get_relation(synonyms, antonyms, word1, word2))

def main():
	(word_no, relation_no, question_no) = [int(number) for number in input().split()]
	input()
	(synonyms, antonyms) = make_relations(relation_no)
	answer_questions(question_no, synonyms, antonyms)
main()


f = lambda : input().split()
(n, m, k) = map(int, f())
u = list(range(n + 1))
v = [n] * n
s = {q: i for (i, q) in zip(u, f())}
p = ['YES'] * m

def g(i):
	k = u[i]
	while k != u[k]:
		k = u[k]
	while u[i] != k:
		(i, u[i]) = (u[i], k)
	return k
for l in range(m):
	(r, x, y) = f()
	(i, j) = (s[x], s[y])
	(a, b) = (g(i), g(j))
	(i, j) = (v[a], v[b])
	(c, d) = (g(i), g(j))
	if r == '2':
		(b, d) = (d, b)
	if a == d:
		p[l] = 'NO'
	elif c == b == n:
		(v[a], v[d]) = (d, a)
	elif c == b:
		p[l] = 'NO'
	elif c == n:
		u[a] = b
	elif b == n:
		u[d] = c
	elif d == n:
		u[b] = a
	else:
		(u[a], u[c]) = (b, d)
u = [g(q) for q in u]
v = [u[q] for q in v]
for l in range(k):
	(x, y) = f()
	(i, j) = (s[x], s[y])
	(a, c) = (u[i], u[j])
	p.append(str(3 - 2 * (a == c) - (a == v[c])))
print('\n'.join(p))


class Union:

	def __init__(self, n):
		self.p = {i: i for i in range(n)}
		self.rank = {i: 1 for i in range(n)}

	def find(self, x):
		if x < 0:
			return x
		if self.p[x] != x:
			self.p[x] = self.find(self.p[x])
		return self.p[x]

	def union(self, x, y):
		if x < 0 or y < 0:
			return
		x = self.find(x)
		y = self.find(y)
		if x != y:
			if self.rank[x] < self.rank[y]:
				self.p[x] = y
				self.rank[y] += self.rank[x]
			else:
				self.p[y] = x
				self.rank[x] += self.rank[y]
(n, m, q) = map(int, input().split())
listW = input().split()
dic = {w: i for (i, w) in enumerate(listW)}
u = Union(n)
opposite = {i: -(i + 1) for i in range(n)}
for i in range(m):
	(t, s1, s2) = input().split()
	x = u.find(dic[s1])
	y = u.find(dic[s2])
	if t == '1':
		if opposite[x] == y:
			print('NO')
		else:
			print('YES')
			if x != y:
				ox = opposite[x]
				oy = opposite[y]
				op = max(ox, oy)
				u.union(x, y)
				u.union(ox, oy)
				op = u.find(op)
				p = u.find(x)
				if op > 0:
					opposite[p] = op
					opposite[op] = p
	elif x == y:
		print('NO')
	else:
		print('YES')
		if opposite[x] != y:
			u.union(y, opposite[x])
			u.union(x, opposite[y])
			x = u.find(x)
			y = u.find(y)
			opposite[x] = y
			opposite[y] = x
for _ in range(q):
	(s1, s2) = input().split()
	(id1, id2) = (u.find(dic[s1]), u.find(dic[s2]))
	if id1 == id2:
		print(1)
	elif opposite[id1] == id2:
		print(2)
	else:
		print(3)


def union(u, v, parent):
	x = find(u, parent)
	y = find(v, parent)
	if x == y:
		return
	parent[x] = y

def find(u, parent):
	k = parent[u]
	while k != parent[k]:
		k = parent[k]
	while parent[u] != k:
		(u, parent[u]) = (parent[u], k)
	return k
(n, m, q) = map(int, input().split())
p = [i for i in range(2 * n)]
d = {}
s = input().split()
for i in range(n):
	d[s[i]] = i
for i in range(m):
	(re, node1, node2) = input().split()
	a1 = find(d[node1], p)
	a2 = find(d[node1] + n, p)
	b1 = find(d[node2], p)
	b2 = find(d[node2] + n, p)
	if re == '1':
		if a1 == b2 or a2 == b1:
			print('NO')
		else:
			print('YES')
			union(d[node1], d[node2], p)
			union(d[node1] + n, d[node2] + n, p)
	elif re == '2':
		if a1 == b1 or a2 == b2:
			print('NO')
		else:
			print('YES')
			union(d[node1], d[node2] + n, p)
			union(d[node1] + n, d[node2], p)
for i in range(q):
	(node1, node2) = input().split()
	a1 = find(d[node1], p)
	a2 = find(d[node1] + n, p)
	b1 = find(d[node2], p)
	b2 = find(d[node2] + n, p)
	if a1 == b1 or a2 == b2:
		print(1)
	elif a1 == b2 or b1 == a2:
		print(2)
	else:
		print(3)