def sta():
	s, t = input(), input()
	assert len(s)==len(t)
	assert 1<=len(s)<=50
	assert s != t

	map_st = {}
	map_ts = {}

	for i in range(len(s)):
		c1, c2 = s[i], t[i]
		if c1 not in map_st: map_st[c1] = c2
		if c2 not in map_ts: map_ts[c2] = c1
		
		if map_st[c1] != c2 or map_ts[c2] != c1: return False
	return True
	

queries = int(input())
assert 1 <= queries <= 50
for _ in range(queries):
	print("YES" if sta() else "NO")