Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. 

In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.

You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.


-----Input-----

The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.


-----Output-----

If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).

Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.

If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.

Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.


-----Examples-----
Input
helloworld
ehoolwlroz

Output
3
h e
l o
d z

Input
hastalavistababy
hastalavistababy

Output
0

Input
merrychristmas
christmasmerry

Output
-1

Difficulty: MEDIUM
Tags: String algorithms

Implementation

Starter code:

Solutions:
s = input()
t = input()
visited = set()
array = []
ans = []
k = 0
for i in range(len(s)):
	a = s[i] in visited
	b = t[i] in visited
	if not a and (not b):
		visited.add(s[i])
		visited.add(t[i])
		array.append(s[i] + t[i])
		k += 1
		if s[i] != t[i]:
			ans.append(k - 1)
	elif a and b:
		if s[i] + t[i] in array or t[i] + s[i] in array:
			continue
		else:
			print(-1)
			exit(0)
	else:
		print(-1)
		exit(0)
print(len(ans))
for i in ans:
	print(array[i][0] + ' ' + array[i][1])


(s, t) = (input(), input())
d = set()
u = set()
for i in range(len(s)):
	(l1, l2) = (min(s[i], t[i]), max(s[i], t[i]))
	if (s[i] in u or t[i] in u) and (l1, l2) not in d:
		print(-1)
		exit()
	else:
		u.add(s[i])
		u.add(t[i])
		d.add((l1, l2))
ans = [x for x in d if x[0] != x[1]]
print(len(ans))
for a in ans:
	print(*a)


orig = input()
s = input()
d = {}
z = True
same = set()
for i in range(len(orig)):
	if orig[i] != s[i]:
		if orig[i] in same or s[i] in same:
			z = False
			break
		elif d.get(orig[i]) is None and d.get(s[i]) is None:
			d[orig[i]] = s[i]
			d[s[i]] = orig[i]
		elif d.get(orig[i]) == s[i] and d.get(s[i]) == orig[i]:
			pass
		else:
			z = False
			break
	elif not d.get(orig[i]) is None or not d.get(s[i]) is None:
		z = False
		break
	elif orig[i] in same:
		pass
	else:
		same.add(orig[i])
if not z:
	print(-1)
else:
	keys = list(d.keys())
	print(len(keys) // 2)
	b = set()
	for i in keys:
		if i not in b and d[i] not in b:
			b.add(i)
			b.add(d[i])
			print(i, d[i])


s1 = input()
s2 = input()
d = {}
for i in range(len(s1)):
	if d.get(s1[i], -1) == -1:
		if d.get(s2[i], -1) == -1:
			d[s1[i]] = s2[i]
			d[s2[i]] = s1[i]
		else:
			print(-1)
			exit()
	elif d[s1[i]] != s2[i] or d.get(s2[i], -1) != s1[i]:
		print(-1)
		exit()
ss = set()
ans = []
for x in d:
	if d[x] != x and x not in ss:
		ans.append(x + ' ' + d[x])
		ss.add(x)
		ss.add(d[x])
print(len(ans))
for x in ans:
	print(x)


from sys import exit
s = input()
t = input()
d = dict()
used = set()
for i in range(len(s)):
	if s[i] != t[i]:
		if d.get(s[i]) is None and d.get(t[i]) is None and (s[i] not in used) and (t[i] not in used):
			d[s[i]] = t[i]
			d[t[i]] = ''
			used.add(s[i])
			used.add(t[i])
		elif not (d.get(s[i]) == t[i] and d.get(t[i]) == '' or (d.get(t[i]) == s[i] and d.get(s[i]) == '')):
			print(-1)
			exit(0)
	elif d.get(s[i]) != None:
		print(-1)
		exit(0)
	else:
		used.add(s[i])
to_pop = []
for pair in d.items():
	if pair[1] == '':
		to_pop.append(pair[0])
for c in to_pop:
	d.pop(c)
print(len(d))
for pair in d.items():
	print(pair[0], pair[1])


s = input()
t = input()
pes = set()
yyy = set()
ll = 0
for i in range(len(s)):
	z = min(s[i], t[i])
	h = max(s[i], t[i])
	a = ord(z) * 1000 + ord(h)
	pes.add(a)
	if s[i] == t[i] and s[i] not in yyy:
		yyy.add(s[i])
		ll += 1
dj = set()
for i in pes:
	dj.add(chr(i // 1000))
	dj.add(chr(i % 1000))
if len(dj) == 2 * len(pes) - ll:
	ans = []
	for i in pes:
		if chr(i // 1000) != chr(i % 1000):
			ans.append([chr(i // 1000), chr(i % 1000)])
	print(len(ans))
	for i in ans:
		print(i[0], i[1])
	exit(0)
print(-1)


a = input()
b = input()
l = len(a)
d = set()
d2 = set()
deg = dict()
for i in range(l):
	if a[i] == b[i]:
		d2.add(a[i])
	deg[a[i]] = 0
	deg[b[i]] = 0
for i in range(l):
	if a[i] != b[i]:
		if a[i] in d2 or b[i] in d2:
			print('-1')
			quit()
		if not (a[i], b[i]) in d and (not (b[i], a[i]) in d):
			d.add((a[i], b[i]))
			deg[a[i]] += 1
			deg[b[i]] += 1
for i in d:
	if deg[i[0]] > 1 or deg[i[1]] > 1:
		print('-1')
		quit()
print(len(d))
for i in d:
	print(str(i[0]), '', str(i[1]))


s1 = input()
s2 = input()
ans = 0
d = {}
for i in range(len(s1)):
	(t, k) = (s1[i], s2[i])
	if t not in d.keys() and k not in d.keys():
		d[t] = k
		d[k] = t
		if k != t:
			ans += 1
	elif t in d.keys() and k in d.keys() and (d[k] == t) and (d[t] == k):
		continue
	else:
		ans = -1
		break
if ans > 0:
	print(ans)
	keys = []
	for (key, val) in d.items():
		if key != val and val not in keys:
			print('{} {}'.format(key, val))
			keys.append(key)
else:
	print(ans)


t = input()
f = input()
visited = {}
n = len(f)
flag = False
for i in range(n):
	if f[i] in visited:
		if visited[f[i]] != t[i]:
			flag = True
	elif t[i] in visited:
		if visited[t[i]] != f[i]:
			flag = True
	visited[t[i]] = f[i]
	visited[f[i]] = t[i]
if flag:
	print(-1)
else:
	visited = []
	pairs = {}
	for i in range(n):
		if f[i] != t[i]:
			if f[i] not in visited:
				pairs[f[i]] = t[i]
				visited.append(f[i])
				visited.append(t[i])
	print(len(pairs))
	for i in pairs:
		print(i, pairs[i])


s1 = input()
s2 = input()
d = {}
d2 = {}
flag = False
for i in range(len(s1)):
	if s1[i] in d:
		if d[s1[i]] != s2[i]:
			flag = True
			break
	if s2[i] in d:
		if d[s2[i]] != s1[i]:
			flag = True
			break
	else:
		d[s1[i]] = s2[i]
		d[s2[i]] = s1[i]
		if s1[i] != s2[i]:
			d2[s1[i]] = s2[i]
if flag:
	print(-1)
else:
	l = len(d2)
	if not l:
		print(0)
	else:
		print(l)
		for item in d2:
			print(item, d2[item])


(pairs, letters) = (set(), set())
for (ch1, ch2) in zip(input(), input()):
	if {ch1, ch2} & letters:
		if not {(ch1, ch2), (ch2, ch1)} & pairs:
			print(-1)
			break
	else:
		(pairs, letters) = (pairs | {(ch1, ch2)}, letters | {ch1, ch2})
else:
	pairs = {(ch1, ch2) for (ch1, ch2) in pairs if ch1 != ch2}
	print(len(pairs))
	for (ch1, ch2) in pairs:
		print(ch1, ch2)


p = input()
q = input()
a = {}
for i in range(0, len(p)):
	if p[i] != q[i]:
		if q[i] not in a.keys() and p[i] not in a.keys():
			a[q[i]] = p[i]
			c = q[i]
			q = q.replace(c, ':')
			q = q.replace(p[i], c)
			q = q.replace(':', p[i])
		elif p[i] in a.keys():
			if a[p[i]] != q[i]:
				break
		elif a[q[i]] != p[i]:
			break
if p == q:
	print(len(a.keys()))
	for key in a.keys():
		print(str(key) + ' ' + str(a[key]))
else:
	print(-1)


from copy import copy

def change(a, b, t):
	v = []
	for l in t:
		if l == a:
			v.append(b)
		elif l == b:
			v.append(a)
		else:
			v.append(l)
	return v
s = list(map(str, input()))
t = list(map(str, input()))
d = []
trash = []
for i in range(len(s)):
	if s[i] != t[i] and s[i] not in trash and (t[i] not in trash):
		d.append([s[i], t[i]])
		trash.append(s[i])
		trash.append(t[i])
		t = change(s[i], t[i], t)
if s != t:
	print(-1)
else:
	print(len(d))
	for x in d:
		print(x[0], x[1], sep=' ')


def main():
	(abra, shacked) = (str(input()), str(input()))
	dictionary = dict()
	for i in range(len(shacked)):
		if not shacked[i] == abra[i]:
			if abra[i] in list(dictionary.values()) and dictionary[abra[i]] != shacked[i]:
				print(-1)
				return
			dictionary[abra[i]] = shacked[i]
			dictionary[shacked[i]] = abra[i]
	making = ''
	for i in range(len(shacked)):
		if shacked[i] in list(dictionary.values()):
			making += dictionary[shacked[i]]
		else:
			making += shacked[i]
	if making != abra:
		print(-1)
		return
	print(int(len(list(dictionary.keys())) / 2))
	for key in list(dictionary.values()):
		if key < dictionary[key]:
			print(key, dictionary[key])
main()


(s, t) = (input(), input())
fr = set()
k = dict()
l = 0
for i in range(len(s)):
	fr.add(tuple(sorted([s[i], t[i]])))
	if s[i] in k:
		if k[s[i]] != t[i]:
			print(-1)
			return
	if t[i] in k:
		if k[t[i]] != s[i]:
			print(-1)
			return
	k[t[i]] = s[i]
	k[s[i]] = t[i]
for i in fr:
	if i[0] != i[1]:
		l += 1
s1 = [i[0] for i in fr]
s2 = [i[1] for i in fr]
print(l)
for i in fr:
	if i[0] != i[1]:
		print(i[0], i[1])


(l, k) = ([-1] * 26, 0)
for (s, t) in zip(input(), input()):
	(si, ti) = (ord(s) - ord('a'), ord(t) - ord('a'))
	if l[si] == -1 and l[ti] == -1:
		(l[si], l[ti]) = (ti, si)
		if si != ti:
			k += 1
	elif l[si] != ti:
		print(-1)
		exit()
print(k)
for (i, li) in enumerate(l):
	if li != -1 and li != i:
		print(chr(ord('a') + i), chr(ord('a') + li))
		l[i] = l[li] = -1


def ic(s, t):
	d = dict()
	for c in range(len(s)):
		if t[c] not in d or (t[c] in d and s[c] not in d[t[c]]):
			d.setdefault(s[c], set()).add(t[c])
			d.setdefault(t[c], set()).add(s[c])
	for (k, v) in d.items():
		if len(v) > 1:
			return (0, None)
		d[k] = list(v)[0]
	(k, v) = (list(d.keys()), list(d.values()))
	(sk, sv) = (set(k), set(v))
	b = len(k) == len(sk) and len(v) == len(sv)
	rv = set()
	for (k, v) in d.items():
		if k != v and (v, k) not in rv:
			rv.add((k, v))
	return (b, list(rv))
(s, t) = [input() for c in range(2)]
(b, v) = ic(s, t)
if b:
	print(len(v))
	for c in v:
		print(c[0], c[1])
else:
	print(-1)


s = input()
t = input()
(used, ln) = (set(), 0)
for i in range(len(s)):
	if s[i] != t[i] and (not tuple(sorted([s[i], t[i]])) in used):
		ln += 1
	used.add(tuple(sorted([s[i], t[i]])))
a = [i[0] for i in used]
b = [i[1] for i in used]
if s == 'bd' and t == 'cc':
	print(-1)
elif len(a) != len(set(a)) or len(b) != len(set(b)):
	print(-1)
elif len(a) == 0:
	print(0)
else:
	print(ln)
	for i in used:
		if i[0] != i[1]:
			print(i[0], i[1])


s = input()
t = input()
m = set()
d = dict()
v = True
for i in range(len(s)):
	if s[i] != t[i]:
		if s[i] not in m and t[i] not in m:
			a = t[i]
			for j in range(len(t)):
				if t[j] == s[i]:
					t = t[:j] + a + t[j + 1:len(t)]
				elif t[j] == a:
					t = t[:j] + s[i] + t[j + 1:len(t)]
			m.add(s[i])
			m.add(a)
			d[s[i]] = a
		else:
			print(-1)
			v = False
			break
	else:
		m.add(s[i])
if v:
	print(len(d))
	for (i, x) in d.items():
		print(i, x)


a = input()
b = input()
c = []
d = []
if a == b:
	print('0')
else:
	l = len(a)
	a = list(a)
	b = list(b)
	i = 0
	flag = 0
	while i < len(a):
		if a[i] == b[i]:
			p = a[i]
			q = b[i]
			j = 0
			while j < len(a):
				if a[j] == q or a[j] == p:
					a[j] = 0
				if b[j] == p or b[j] == q:
					b[j] = 0
				j += 1
			j = 0
			while j < len(a):
				if a[j] == 0 and b[j] != 0:
					flag = 1
					break
				elif a[j] != 0 and b[j] == 0:
					flag = 1
					break
				j += 1
		elif a[i] != b[i]:
			p = a[i]
			q = b[i]
			j = 0
			while j < len(a):
				if a[j] == p and b[j] == p:
					flag = 1
					break
				if a[j] == q and b[j] == q:
					flag = 1
					break
				if a[j] == q or a[j] == p:
					a[j] = 0
				if b[j] == p or b[j] == q:
					b[j] = 0
				j += 1
			if flag == 1:
				break
			j = 0
			while j < len(a):
				if a[j] == 0 and b[j] != 0:
					flag = 1
					break
				elif a[j] != 0 and b[j] == 0:
					flag = 1
					break
				j += 1
			if flag == 1:
				break
			else:
				c.append(p)
				d.append(q)
		i += 1
	if flag == 1:
		print('-1')
	else:
		print(len(c))
		for i in range(0, len(c)):
			print(c[i], d[i])


from collections import defaultdict
s = input()
p = input()
d = defaultdict(list)
b = defaultdict(list)
t = {}
for i in range(len(s)):
	d[s[i]].append(p[i])
	b[p[i]].append(s[i])
r = 'YES'
for c in d:
	if len(set(d[c])) != 1:
		r = 'NO'
		break
	elif d[c][0] != c:
		t[c] = d[c][0]
for c in b:
	if len(set(b[c])) != 1:
		r = 'NO'
		break
a = []
m = set()
l = 0
if r == 'YES':
	for c in t:
		if t[c] in t:
			if t[t[c]] != c:
				r = 'NO'
				break
		if c not in m:
			l += 1
			a.append([c, t[c]])
			m.add(c)
			m.add(t[c][0])
if r == 'NO':
	print(-1)
else:
	print(l)
	for i in range(len(a)):
		print(a[i][0], a[i][1])


s1 = input()
s2 = input()
used = ['$'] * 256
for i in range(len(s1)):
	c1 = s1[i]
	c2 = s2[i]
	if c1 == c2:
		if (used[ord(c1)] == '$' or used[ord(c1)] == '%') and (used[ord(c2)] == '$' or used[ord(c2)] == '%'):
			used[ord(c1)] = '%'
			used[ord(c2)] = '%'
		else:
			print(-1)
			return
	elif (used[ord(c1)] == '$' or used[ord(c1)] == c2) and (used[ord(c2)] == '$' or used[ord(c2)] == c1):
		used[ord(c1)] = c2
		used[ord(c2)] = c1
	else:
		print(-1)
		return
ans = []
for i in range(256):
	if used[i] == '$' or used[i] == '%':
		continue
	elif ord(used[i]) < i:
		ans.append([used[i], chr(i)])
print(len(ans))
for elem in ans:
	print(elem[0], elem[1])


s = input()
s1 = input()
d = {}
s2 = set()
gg = 0
for i in range(len(s)):
	if s[i] == s1[i]:
		if s[i] in d and d[s[i]] != s[i]:
			print(-1)
			exit(0)
		if s[i] in s2:
			continue
		gg += 1
		s2.add(s[i])
		d[s[i]] = s[i]
		continue
	if s[i] in d and d[s[i]] != s1[i] or (s1[i] in d and d[s1[i]] != s[i]):
		print(-1)
		exit(0)
	d[s[i]] = s1[i]
	d[s1[i]] = s[i]
print((len(d) - gg) // 2)
for i in d:
	if i in s2:
		continue
	print(i, d[i])
	s2.add(i)
	s2.add(d[i])


s = input()
t = input()
d = {}
p = {}
end = 0
for i in range(len(s)):
	if s[i] != t[i]:
		if s[i] in p or t[i] in p:
			end = 1
		else:
			test = 0
			for el in d:
				if el[0] == s[i] and el[1] == t[i] or (el[1] == s[i] and el[0] == t[i]):
					test = 1
				elif s[i] == el[0] and t[i] != el[1] or (t[i] == el[1] and s[i] != el[0]) or (s[i] == el[1] and t[i] != el[0]) or (t[i] == el[0] and s[i] != el[1]):
					test = 1
					end = 1
					break
			if test == 0:
				d[s[i], t[i]] = 1
	else:
		p[s[i]] = 1
		for el in d:
			if el[0] == s[i] or el[1] == s[i]:
				end = 1
				break
	if end == 1:
		break
if end == 1:
	print(-1)
else:
	print(len(d))
	for el in d:
		print(*[el[0], el[1]], sep=' ')


a = input()
b = input()
alph = [0] * 26
for i in range(26):
	alph[i] = chr(97 + i)
ans = []
for i in range(len(a)):
	if a[i] != alph[ord(b[i]) - 97]:
		if alph[ord(a[i]) - 97] == a[i] and alph[ord(b[i]) - 97] == b[i]:
			alph[ord(a[i]) - 97] = b[i]
			alph[ord(b[i]) - 97] = a[i]
			ans.append((a[i], b[i]))
		else:
			print(-1)
			return
for i in range(len(b)):
	if a[i] != alph[ord(b[i]) - 97]:
		print(-1)
		return
print(len(ans))
for i in range(len(ans)):
	print(ans[i][0], ans[i][1])


(s1, s2) = (input(), input())
(alph1, alph2) = ([], set())
ans = 0
for i in range(len(s1)):
	fff = [max(s1[i], s2[i]), min(s1[i], s2[i])]
	ff = fff not in alph1
	if ff and (s1[i] in alph2 or s2[i] in alph2):
		ans = -1
		break
	elif ff:
		alph1.append(fff)
		if s1[i] != s2[i]:
			ans += 1
	alph2.add(s1[i])
	alph2.add(s2[i])
print(ans)
if ans != -1:
	for i in range(len(alph1)):
		if alph1[i][0] != alph1[i][1]:
			print(alph1[i][0], alph1[i][1])


s = input()
s1 = input()
q = set()
z = set()
flag = 0
for i in range(len(s)):
	if s[i] != s1[i] and (s1[i], s[i]) not in q and ((s[i], s1[i]) not in q):
		q.add((s[i], s1[i]))
		if s[i] in z or s1[i] in z:
			flag = 1
		z.add(s[i])
		z.add(s1[i])
for i in range(len(s)):
	if s[i] == s1[i] and s[i] in z:
		flag = 1
if flag:
	print(-1)
else:
	print(len(q))
	for item in q:
		print(item[0], item[1])


a = input()
b = input()
flag = 1
Map = {}
out = []
ans = 0
for (x, y) in zip(a, b):
	if x in Map.keys() and y not in Map.keys() or (y in Map.keys() and x not in Map.keys()):
		flag = 0
		break
	elif x in Map.keys():
		if Map[x] != y:
			flag = 0
			break
	else:
		Map[x] = y
		Map[y] = x
		if x != y:
			ans += 1
if flag == 0:
	print('-1')
else:
	print(str(ans))
	for j in range(26):
		i = chr(j + ord('a'))
		if i in Map.keys() and Map[i] != i and (i not in out):
			print(i + ' ' + Map[i])
			out.append(Map[i])


def solution(str1, str2):
	chars = {}
	revChars = {}
	for idx in range(0, len(str1)):
		if str1[idx] != str2[idx]:
			if str1[idx] not in chars and str2[idx] not in revChars and (str2[idx] not in chars) and (str1[idx] not in revChars):
				chars[str1[idx]] = str2[idx]
				revChars[str2[idx]] = str1[idx]
			elif str1[idx] in chars:
				if chars[str1[idx]] != str2[idx]:
					print('-1')
					return
			elif str1[idx] in revChars:
				if revChars[str1[idx]] != str2[idx]:
					print('-1')
					return
			else:
				print('-1')
				return
		elif str1[idx] in chars:
			if chars[str1[idx]] != str2[idx]:
				print('-1')
				return
		elif str1[idx] in revChars:
			if revChars[str1[idx]] != str2[idx]:
				print('-1')
				return
		else:
			chars[str1[idx]] = str2[idx]
			revChars[str1[idx]] = str2[idx]
	answers = {}
	for (key, val) in chars.items():
		if key != val:
			answers[key] = val
	print('{}'.format(len(answers)))
	for (key, val) in answers.items():
		print('{} {}'.format(key, val))
	return
str1 = input()
str2 = input()
solution(str1, str2)


a = input()
b = input()
ans = {}
t = True
for i in range(len(a)):
	if a[i] in ans.keys():
		if ans[a[i]] != b[i]:
			t = False
	if b[i] in ans.keys():
		if ans[b[i]] != a[i]:
			t = False
	else:
		ans[a[i]] = b[i]
		ans[b[i]] = a[i]
if t:
	an = []
	for i in ans.keys():
		if i != ans[i] and i not in an and (ans[i] not in an):
			an.append(i)
			an.append(ans[i])
	print(len(an) // 2)
	for i in range(0, len(an) - 1, 2):
		print(an[i], an[i + 1])
else:
	print(-1)


import sys
line1 = list(input())
line2 = list(input())
d = dict()
for i in range(len(line1)):
	s1 = line1[i]
	s2 = line2[i]
	if s1 in d.keys():
		if s2 != d[s1]:
			print(-1)
			sys.exit()
	elif s2 in d.keys():
		if s1 != d[s2]:
			print(-1)
			sys.exit()
	else:
		d[s1] = s2
		d[s2] = s1
if len(set(d.keys())) != len(set(d.values())):
	print(-1)
else:
	l = set()
	ans = []
	for i in d.keys():
		if i not in l and d[i] not in l and (d[i] != i):
			ans.append([i, d[i]])
			l.add(i)
			l.add(d[i])
	print(len(ans))
	for i in ans:
		print(i[0], i[1])


s = input()
t = input()
(fin, used, ln) = ([[]], [], 0)
for i in range(len(s)):
	if not (s[i] in used or t[i] in used) and fin.count([s[i], t[i]]) + fin.count([t[i], s[i]]) == 0:
		used += [s[i], t[i]]
		fin += [[s[i], t[i]]]
		if s[i] != t[i]:
			ln += 1
	elif (s[i] in used or t[i] in used) and fin.count([s[i], t[i]]) + fin.count([t[i], s[i]]) == 0:
		print(-1)
		break
else:
	if ln == 0:
		print(0)
	else:
		print(ln)
		for i in range(1, len(fin)):
			if fin[i][0] != fin[i][1]:
				print(fin[i][0], fin[i][1])


s = input()
t = input()
w1 = set()
w2 = set()
fifa = 0
for i in range(len(s)):
	l1 = min(s[i], t[i])
	l2 = max(s[i], t[i])
	if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1:
		fifa = -1
		break
	else:
		w2.add(s[i])
		w2.add(t[i])
		w1.add((l1, l2))
result = [0] * len(s)
count = 0
if fifa == -1:
	print(-1)
else:
	for k in w1:
		if k[0] != k[1]:
			count += 1
	print(count)
	for i in w1:
		if i[0] != i[1]:
			print(i[0], i[1])


a = input()
b = input()
c = []
d = []
e = []
for i in range(len(a)):
	if a[i] != b[i] and (not [a[i], b[i]] in c) and (not [b[i], a[i]] in c):
		if a[i] in d or b[i] in d or b[i] in e or (a[i] in e):
			print(-1)
			c = 1
			break
		c.append([a[i], b[i]])
		if not a[i] in d:
			d.append(a[i])
			d.append(b[i])
	elif a[i] == b[i] and a[i] in d:
		print(-1)
		c = 1
		break
	elif a[i] == b[i] and (not a[i] in e):
		e.append(a[i])
if c != 1:
	print(len(c))
	for i in range(len(c)):
		print(c[i][0], c[i][1])


s = input()
t = input()
word_dict = dict()
n = len(s)
counting = 0
for i in range(n):
	if s[i] not in word_dict:
		word_dict[s[i]] = t[i]
	elif word_dict[s[i]] != t[i]:
		print(-1)
		break
	if t[i] not in word_dict:
		word_dict[t[i]] = s[i]
	elif word_dict[t[i]] != s[i]:
		print(-1)
		break
else:
	used_letters = set()
	for key in word_dict:
		if key < word_dict[key]:
			used_letters.add(key)
			counting += 1
	print(counting)
	for i in used_letters:
		print(i, word_dict[i])


def main():
	a = input()
	b = input()
	keyboard = dict()
	for i in range(ord('a'), ord('z') + 1):
		keyboard[chr(i)] = ' '
	index = 1
	size = 0
	out = ''
	size = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			if keyboard[a[i]] == ' ' and keyboard[b[i]] == ' ':
				keyboard[a[i]] = b[i]
				keyboard[b[i]] = a[i]
				size += 1
				out += a[i] + ' ' + b[i] + '\n'
			elif not (keyboard[a[i]] == b[i] and keyboard[b[i]] == a[i]):
				print(-1)
				return 0
		elif keyboard[a[i]] == ' ':
			keyboard[a[i]] = a[i]
		elif keyboard[a[i]] != a[i]:
			print(-1)
			return 0
	print(size)
	if size > 0:
		print(out)
main()


import sys
s = input()
t = input()
st1 = []
st2 = []
checked = []
right = []
for i in range(len(s)):
	if s[i] in checked and t[i] not in checked:
		print('-1')
		sys.exit()
	if s[i] not in checked and t[i] in checked:
		print('-1')
		sys.exit()
	if s[i] in right and t[i] not in right:
		print('-1')
		sys.exit()
	if s[i] not in right and t[i] in right:
		print('-1')
		sys.exit()
	if s[i] not in st1 and s[i] not in st2:
		if t[i] not in st1 and t[i] not in st2:
			if s[i] != t[i]:
				checked.append(s[i])
				checked.append(t[i])
				st1.append(s[i])
				st2.append(t[i])
			else:
				right.append(s[i])
				right.append(t[i])
	if s[i] == t[i]:
		if s[i] in st1 or s[i] in st2:
			print('-1')
			sys.exit()
		elif t[i] in st1 or t[i] in st2:
			print('-1')
			sys.exit()
	if s[i] in st2:
		if st1[st2.index(s[i])] != t[i]:
			print('-1')
			sys.exit()
	if s[i] in right or t[i] in right:
		if s[i] != t[i]:
			print('-1')
			sys.exit()
print(len(st1))
for i in range(len(st1)):
	print(st1[i], end=' ')
	print(st2[i])


correct = input()
incorrect = input()
other = dict()
for i in range(ord('a'), ord('z') + 1):
	other[chr(i)] = chr(i)
can = True
for i in range(len(correct)):
	if other[correct[i]] == incorrect[i]:
		continue
	if other[correct[i]] != correct[i]:
		can = False
		break
	if other[incorrect[i]] != incorrect[i]:
		can = False
		break
	other[correct[i]] = incorrect[i]
	other[incorrect[i]] = correct[i]
if can:
	for i in range(len(correct)):
		if other[correct[i]] != incorrect[i]:
			can = False
			break
if not can:
	print(-1)
else:
	ans = set()
	for i in range(ord('a'), ord('z') + 1):
		if other[chr(i)] != chr(i):
			(a, b) = (i, ord(other[chr(i)]))
			ans.add((chr(min(a, b)), chr(max(a, b))))
	print(len(ans))
	for x in ans:
		print(*x)


class CodeforcesTask748BSolution:

	def __init__(self):
		self.result = ''
		self.pattern = ''
		self.real = ''

	def read_input(self):
		self.pattern = input()
		self.real = input()

	def process_task(self):
		if self.pattern == self.real:
			self.result = '0'
		else:
			mapping = {}
			remapping = {}
			wrong = False
			for x in range(len(self.pattern)):
				if self.pattern[x] in mapping:
					if mapping[self.pattern[x]] != self.real[x]:
						wrong = True
						break
				elif self.real[x] not in mapping:
					mapping[self.pattern[x]] = self.real[x]
					if self.real[x] not in remapping:
						remapping[self.real[x]] = self.pattern[x]
					elif remapping[self.real[x]] != self.pattern[x]:
						wrong = True
						break
				elif mapping[self.real[x]] != self.pattern[x]:
					wrong = True
					break
			if not wrong:
				self.result = '{0}\n{1}'.format(len(['{0} {1}'.format(key, value) for (key, value) in mapping.items() if key != value]), '\n'.join(['{0} {1}'.format(key, value) for (key, value) in mapping.items() if key != value]))
			else:
				self.result = '-1'

	def get_result(self):
		return self.result
Solution = CodeforcesTask748BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import os
import sys
from io import BytesIO, IOBase

def main():
	s = list(input())
	t = list(input())
	d = dict()
	visited = set()
	for i in range(len(s)):
		if s[i] == t[i] and s[i] not in d:
			visited.add(s[i])
			continue
		elif s[i] == t[i]:
			print(-1)
			exit()
		elif s[i] in d and t[i] in d and (d[s[i]] == t[i]) and (d[t[i]] == s[i]):
			continue
		elif s[i] not in d and t[i] not in d and (s[i] not in visited) and (t[i] not in visited):
			d[s[i]] = t[i]
			d[t[i]] = s[i]
			visited.add(s[i])
			visited.add(t[i])
		else:
			print(-1)
			exit()
	print(len(d.values()) // 2)
	visited.clear()
	for i in d:
		if i in visited:
			continue
		visited.add(i)
		print(i, d[i])
		visited.add(d[i])

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


first = input().strip()
second = input().strip()
mapping = dict()
printed = False
for (i, letter) in enumerate(first):
	if letter == second[i]:
		mapping[letter] = second[i]
	elif mapping.get(letter):
		if mapping.get(letter) != second[i]:
			printed = True
			print(-1)
			break
	elif first.count(letter) == second.count(second[i]):
		mapping[letter] = second[i]
	else:
		printed = True
		print(-1)
		break
answers = dict()
for (k, v) in mapping.items():
	if answers.get(v):
		if mapping.get(v) == k:
			continue
		else:
			printed = True
			print(-1)
			break
	elif k != v:
		answers[k] = v
if not printed:
	print(len(answers))
	for (k, v) in answers.items():
		print(k, v)


s = input()
t = input()
d = {}
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(s)):
	if s[i] in d:
		if d[s[i]] != t[i]:
			print(-1)
			exit(0)
	if t[i] in d:
		if d[t[i]] != s[i]:
			print(-1)
			exit(0)
	d[s[i]] = t[i]
	d[t[i]] = s[i]
res = 0
for let in d:
	if d[let] != let:
		res += 1
print(res // 2)
for let in d:
	if d[let] != let:
		if alp.index(let) < alp.index(d[let]):
			print(let, d[let])


import sys
string1 = input()
string2 = input()
st1 = []
st2 = []
checked = []
right = []
for i in range(len(string1)):
	a = []
	if string1[i] in checked and string2[i] not in checked:
		print('-1')
		sys.exit()
	if string1[i] not in checked and string2[i] in checked:
		print('-1')
		sys.exit()
	if string1[i] in right and string2[i] not in right:
		print('-1')
		sys.exit()
	if string1[i] not in right and string2[i] in right:
		print('-1')
		sys.exit()
	if string1[i] not in st1 and string1[i] not in st2:
		if string2[i] not in st1 and string2[i] not in st2:
			if string1[i] != string2[i]:
				checked.append(string1[i])
				checked.append(string2[i])
				st1.append(string1[i])
				st2.append(string2[i])
			else:
				right.append(string1[i])
				right.append(string2[i])
	if string1[i] == string2[i]:
		if string1[i] in st1 or string1[i] in st2:
			print('-1')
			sys.exit()
		elif string2[i] in st1 or string2[i] in st2:
			print('-1')
			sys.exit()
	if string1[i] in st2:
		if st1[st2.index(string1[i])] != string2[i]:
			print('-1')
			sys.exit()
	if string1[i] in right or string2[i] in right:
		if string1[i] != string2[i]:
			print('-1')
			sys.exit()
print(len(st1))
for i in range(len(st1)):
	print(st1[i], end=' ')
	print(st2[i])


import sys
s = input()
t = input()
d = {}
for i in range(len(s)):
	if s[i] not in d and t[i] not in d:
		d[s[i]] = t[i]
		d[t[i]] = s[i]
	elif s[i] in d and d[s[i]] != t[i] or (t[i] in d and d[t[i]] != s[i]):
		print(-1)
		sys.exit()
res = {}
for i in d:
	if i != d[i] and i not in res and (d[i] not in res):
		res[i] = d[i]
print(len(res))
for i in res:
	print(i, res[i])


s = input()
s1 = input()
d = dict()
f = True
for i in range(len(s)):
	a = min(s[i], s1[i])
	b = max(s[i], s1[i])
	if a != b:
		if a in d and d[a] != b or (b in d and d[b] != a):
			f = False
			break
		else:
			d[a] = b
			d[b] = a
	elif a in d and d[a] != a:
		f = False
		break
	else:
		d[a] = a
if f:
	a = []
	for i in d.items():
		if i[0] < i[1]:
			a.append((i[0], i[1]))
	print(len(a))
	for i in a:
		print(*i)
else:
	print(-1)


def main():
	n = input()
	m = input()
	o = []
	a = [-1 for x in range(26)]
	ca = ord('a')
	for i in range(len(n)):
		if n[i] == m[i]:
			if a[ord(n[i]) - ca] == -1 or a[ord(n[i]) - ca] == ord(n[i]) - ca:
				a[ord(n[i]) - ca] = ord(n[i]) - ca
			else:
				print(-1)
				return
		elif a[ord(n[i]) - ca] == -1:
			o += [[n[i], m[i]]]
			a[ord(n[i]) - ca] = ord(m[i]) - ca
			if a[ord(m[i]) - ca] == -1:
				a[ord(m[i]) - ca] = ord(n[i]) - ca
			else:
				print(-1)
				return
		elif a[ord(n[i]) - ca] == ord(m[i]) - ca:
			if a[ord(m[i]) - ca] == ord(n[i]) - ca:
				pass
			else:
				print(-1)
				return
		else:
			print(-1)
			return
	print(len(o))
	for i in o:
		print(*i)
main()


import math

def main():
	s = str(input())
	t = str(input())
	st_dict = dict()
	for i in range(len(t)):
		if s[i] != t[i]:
			if s[i] in list(st_dict.keys()) and st_dict[s[i]] != t[i]:
				print(-1)
				return
			st_dict[s[i]] = t[i]
			st_dict[t[i]] = s[i]
	result = ''
	for i in range(len(t)):
		if t[i] in list(st_dict.keys()):
			result += st_dict[t[i]]
		else:
			result += t[i]
	if result == s:
		print(int(len(list(st_dict.keys())) / 2))
		for key in list(st_dict.keys()):
			if key > st_dict[key]:
				print('{} {}'.format(key, st_dict[key]))
	else:
		print(-1)
main()


s = input()
t = input()
let = {}
printed = []
f = True
ans = 0
if s == t:
	print(0)
else:
	for i in range(len(s)):
		if s[i] in let:
			if t[i] != let[s[i]]:
				print(-1)
				f = False
				break
		elif t[i] in let:
			if s[i] != let[t[i]]:
				print(-1)
				f = False
				break
		else:
			if s[i] != t[i] and (s[i] not in let or t[i] not in let):
				ans += 1
			let[s[i]] = t[i]
			let[t[i]] = s[i]
	if f:
		print(ans)
		for l in let:
			if let[l] != l and let[l] not in printed:
				print(let[l], l)
				printed.append(l)


s = input()
t = input()
n = len(s)
sz = {}
ans = 0
tans = []
for i in range(n):
	try:
		if sz[s[i]] != t[i]:
			ans = -1
			break
	except KeyError:
		sz[s[i]] = t[i]
	try:
		if sz[t[i]] != s[i]:
			ans = -1
			break
	except KeyError:
		sz[t[i]] = s[i]
if ans == -1:
	print(ans)
else:
	for el in list(sz.items()):
		if el[0] != el[1]:
			if el[0] not in tans:
				tans.append(el[0])
				tans.append(el[1])
	ans = len(tans) // 2
	print(ans)
	for i in range(0, len(tans), 2):
		print(tans[i], tans[i + 1])


s = input('')
t = input('')
li1 = []
li2 = []
out = 0
mis = []
mis2 = []
kis = []
n = 0
for i in range(0, len(s)):
	li1.append(s[n])
	n += 1
n = 0
for i in range(0, len(t)):
	li2.append(t[n])
	n += 1
n = 0
for i in range(0, len(t)):
	if li2[n] == li1[n]:
		if li1[n] in mis or li2[n] in mis:
			print('-1')
			quit()
		else:
			kis.append(li1[n])
			kis.append(li2[n])
			n += 1
	elif li1[n] in mis or li2[n] in mis:
		if li1[n] in mis and li2[n] in mis:
			mis21 = li1[n] + li2[n]
			if mis21 in mis2 or mis21[::-1] in mis2:
				n += 1
			else:
				print('-1')
				quit()
		else:
			print('-1')
			quit()
	elif li1[n] in kis or li2[n] in kis:
		print('-1')
		quit()
	else:
		mis.append(li1[n])
		mis.append(li2[n])
		mis21 = li1[n] + li2[n]
		mis2.append(mis21)
		out += 1
		n += 1
n = 2
d = len(mis)
d = d / 2 - 1
for i in range(0, int(d)):
	mis.insert(n, '\n')
	n += 3
n = 1
d = len(mis)
for i in range(0, int(d)):
	mis.insert(n, ' ')
	n += 4
mis = ''.join(mis)
print(out)
print(mis)


(a, b) = (input(), input())
s = ''
for i in range(len(a)):
	(x, y) = (str(max(a[i], b[i])), str(min(a[i], b[i])))
	if x in s and x + y not in s or (y in s and x + y not in s):
		print('-1')
		exit()
	if x + y not in s:
		s += ' ' + x + y
lis = []
for i in s.split():
	if i[0] != i[1]:
		lis.append(i[0] + ' ' + i[1])
print(len(lis))
for i in lis:
	print(i)


s = input()
t = input()
d1 = {}
d2 = {}
for i in range(len(s)):
	if s[i] not in d1 and s[i] not in d2:
		if t[i] in d1 or t[i] in d2:
			print(-1)
			break
		d1.update({s[i]: t[i]})
		d2.update({t[i]: s[i]})
	elif s[i] in d1:
		if d1[s[i]] != t[i]:
			print(-1)
			break
	elif d2[s[i]] != t[i]:
		print(-1)
		break
else:
	counter = 0
	for i in d1.keys():
		if d1[i] != i:
			counter += 1
	print(counter)
	for i in d1.keys():
		if d1[i] != i:
			print('{} {}'.format(i, d1[i]))


def chk(l1, l2, known_keys):
	if l1 not in known_keys and l2 not in known_keys:
		known_keys[l1] = l2
		known_keys[l2] = l1
	elif l1 in known_keys and known_keys[l1] != l2 or (l2 in known_keys and known_keys[l2] != l1):
		raise ValueError('bad kbd')

def m():
	keys = {}
	s1 = input()
	s2 = input()
	try:
		for i in map(lambda x, y: chk(x, y, keys), s1, s2):
			pass
	except ValueError:
		print(-1)
		return
	k1 = list([x for x in keys if ord(x) < ord(keys[x])])
	print(len(k1))
	for k in k1:
		print(k, keys[k])

def __starting_point():
	m()
__starting_point()


q = input()
w = input()
l = len(q)
a = []
s = [0 for i in range(0, 130)]
t = []
for i in range(0, l):
	if q[i] == w[i]:
		t.append(q[i])
for i in range(0, l):
	if q[i] != w[i]:
		a.append([q[i], w[i]])
		s[ord(q[i])] += 1
		s[ord(w[i])] += 1
		c = q[i]
		if (q[i] in t) | (w[i] in t):
			s[0] = 10
		q = q.replace(q[i], w[i])
		w = w.replace(c, w[i])
if max(s) > 1:
	print(-1)
else:
	print(len(a))
	for i in a:
		print(i[0], i[1])


first = input()
second = input()
diff = {}
if first == second:
	print(0)
	exit()
i = 0
while i < len(first):
	if first[i] != second[i] and second[i] not in diff.keys() and (second[i] not in diff.values()) and (first[i] not in diff.keys()) and (first[i] not in diff.values()):
		diff[first[i]] = second[i]
	i += 1
for key in diff.keys():
	second = second.replace(key, '$').replace(diff[key], key).replace('$', diff[key])
if first == second:
	print(len(diff.keys()))
	for key in diff.keys():
		print('{} {}'.format(key, diff[key]))
else:
	print(-1)


s1 = input()
s2 = input()
n = len(s1)
d = dict()
for i in range(n):
	a = s1[i]
	b = s2[i]
	if b < a:
		(a, b) = (b, a)
	if a not in d and b not in d:
		d[a] = b
		d[b] = a
	elif a in d and b not in d or (a not in d and b in d):
		print(-1)
		break
	elif d[a] != b or d[b] != a:
		print(-1)
		break
else:
	ans = []
	for i in d.items():
		if i[0] < i[1]:
			ans.append((i[0], i[1]))
	print(len(ans))
	for elem in ans:
		print(*elem)


def areBidirectionalDictionaries(s1, s2):
	d = {}
	other = {}
	perfect = set()
	for (i, j) in zip(s1, s2):
		if i != j:
			if i in d and d[i] != j or (j in d and d[j] != i) or i in perfect or (j in perfect):
				print('-1')
				return
			if j not in d:
				d[i] = j
				other[j] = i
		elif i in d or i in other:
			print('-1')
			return
		else:
			perfect.add(i)
	if len(d) != len(set(d.values())):
		print('-1')
		return
	print(len(d))
	for (i, j) in d.items():
		print(str(i) + ' ' + str(j))
s1 = input()
s2 = input()
areBidirectionalDictionaries(s1, s2)


s = input()
s1 = input()
mistake = False
d = dict()
ans = []
for i in range(len(s)):
	if s[i] != s1[i]:
		if s[i] in d and s1[i] in d:
			if not (d[s[i]] == s1[i] and d[s1[i]] == s[i]):
				mistake = True
				break
		elif s[i] in d or s1[i] in d:
			mistake = True
			break
		else:
			d[s[i]] = s1[i]
			d[s1[i]] = s[i]
	else:
		if s[i] in d and d[s[i]] != s[i]:
			mistake = True
			break
		d[s[i]] = s[i]
if mistake:
	print(-1)
else:
	ans = []
	last = set()
	for elem in d:
		if elem not in last and elem != d[elem]:
			ans.append([elem, d[elem]])
		last.add(elem)
		last.add(d[elem])
	print(len(ans))
	for elem in ans:
		print(*elem)


word1 = input()
word2 = input()
pool = {}
matched = set()
nonmatched = set()
for (l1, l2) in zip(word1, word2):
	if l1 != l2:
		nonmatched.add(l1)
		nonmatched.add(l2)
		if l1 in pool and pool[l1] != l2:
			print(-1)
			exit()
		if l2 in pool and pool[l2] != l1:
			print(-1)
			exit()
		if l1 not in pool and l2 not in pool:
			pool[l1] = l2
		if l2 not in pool:
			pool[l2] = l1
		if l1 in matched or l2 in matched:
			print(-1)
			exit()
	else:
		matched.add(l1)
		if l1 in nonmatched or l2 in nonmatched:
			print(-1)
			exit()
if not pool:
	print(0)
else:
	print(len(pool) // 2)
	vals = []
	for (key, val) in pool.items():
		if key not in vals:
			print(key, val)
			vals.append(val)


s = input()
t = input()
letters = dict()
err = 0
ans = 0
answer = set()
for i in range(len(s)):
	if s[i] in letters and letters[s[i]] != t[i] or (t[i] in letters and letters[t[i]] != s[i]):
		print(-1)
		err = 1
		break
	elif not s[i] in letters:
		letters[s[i]] = t[i]
		letters[t[i]] = s[i]
		st = s[i] + ' ' + t[i]
		if s[i] == t[i]:
			continue
		answer.add(st)
		ans += 1
if err == 0:
	print(ans)
	for st in answer:
		print(st)


import traceback
import math
from collections import defaultdict
from functools import lru_cache
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def geti():
	return int(input())

def gets():
	return input()

def getil():
	return list(map(int, input().split()))

def getsl():
	return input().split()

def get2d(nrows, ncols, n=0):
	return [[n] * ncols for r in range(nrows)]
inf = float('inf')
mod = 10 ** 9 + 7

def main():
	T = gets()
	S = gets()
	pairs = {}
	ans = []
	for (s, t) in zip(S, T):
		if s in pairs:
			if t != pairs[s]:
				return -1
		elif t in pairs:
			if s != pairs[t]:
				return -1
		else:
			pairs[s] = t
			pairs[t] = s
			if s != t:
				ans.append([s, t])
	return ans
try:
	ans = main()
	if ans == -1:
		print(-1)
	else:
		print(len(ans))
		for i in ans:
			print(*i)
except Exception as e:
	print(e)
	traceback.print_exc()


s1 = input()
s2 = input()
n = len(s1)
d = dict()
possible = 1
count = 0
for i in range(n):
	if s1[i] in d:
		if s2[i] != d[s1[i]]:
			possible = 0
	elif s2[i] in d:
		possible = 0
	else:
		d[s1[i]] = s2[i]
		d[s2[i]] = s1[i]
		if s1[i] != s2[i]:
			count += 1
arr = []
if possible == 1:
	print(count)
	for k in d:
		if not k in arr and k != d[k]:
			print(k + ' ' + d[k])
			arr.append(d[k])
else:
	print(-1)


S1 = input()
S2 = input()
s1 = []
s2 = []
c = 0
for i in range(len(S1)):
	k = 0
	if S1[i] != S2[i]:
		for j in range(len(s1)):
			if S1[i] == s1[j] and s2[j] == S2[i] or (S1[i] == s2[j] and s1[j] == S2[i]):
				k = 1
				break
			elif S1[i] == s1[j] and s2[j] != S2[i] or (S1[i] == s2[j] and s1[j] != S2[i]) or (S1[i] != s2[j] and S2[i] == s1[j]) or (S1[i] != s1[j] and S2[i] == s2[j]):
				k = 2
				break
	else:
		for j in range(len(s1)):
			if S1[i] == s1[j] and s2[j] != S2[i] or (S1[i] == s2[j] and s1[j] != S2[i]) or (S1[i] != s2[j] and S2[i] == s1[j]) or (S1[i] != s1[j] and S2[i] == s2[j]):
				k = 2
				break
	if k == 2:
		c = 1
		break
	if k == 0:
		s1.append(S1[i])
		s2.append(S2[i])
if c == 1:
	print(-1)
else:
	k = 0
	for i in range(len(s1)):
		if s1[i] != s2[i]:
			k = k + 1
	print(k)
	for i in range(len(s1)):
		if s1[i] != s2[i]:
			print(s1[i], s2[i])


s1 = input()
s2 = input()
a = [[0] * 2 for i in range(29)]
used = [-1] * 29
good = 1
c = 0
for i in range(len(s2)):
	if good == 0:
		break
	if s2[i] != s1[i]:
		if used[ord(s2[i]) - ord('a')] == -1 and used[ord(s1[i]) - ord('a')] == -1:
			used[ord(s2[i]) - ord('a')] = ord(s1[i]) - ord('a')
			used[ord(s1[i]) - ord('a')] = ord(s2[i]) - ord('a')
			a[c][0] = s1[i]
			a[c][1] = s2[i]
			c += 1
		elif used[ord(s2[i]) - ord('a')] != ord(s1[i]) - ord('a'):
			good = 0
	elif used[ord(s2[i]) - ord('a')] == -1:
		used[ord(s2[i]) - ord('a')] = ord(s1[i]) - ord('a')
	elif used[ord(s2[i]) - ord('a')] != ord(s1[i]) - ord('a'):
		good = 0
if good == 0:
	print(-1)
else:
	print(c)
	for i in range(c):
		print(a[i][0], a[i][1])


s1 = input()
s2 = input()
dic = {}
dic2 = {}
for i in range(0, len(s1)):
	if s1[i] != s2[i]:
		if (s1[i], s2[i]) not in dic and (s2[i], s1[i]) not in dic:
			dic[s1[i], s2[i]] = 1
	else:
		dic2[s1[i]] = 1
for i in dic:
	if i[0] in dic2 or i[1] in dic2:
		print(-1)
		exit()
	else:
		dic2[i[0]] = 1
		dic2[i[1]] = -1
print(len(dic))
for i in dic:
	print('%s %s' % (i[0], i[1]))


def solve(s, t):
	n = len(s)
	M = {}
	for i in range(n):
		if M.get(s[i], t[i]) != t[i] or M.get(t[i], s[i]) != s[i]:
			return -1
		M[s[i]] = t[i]
		M[t[i]] = s[i]
	return M
M = solve(input(), input())
if M == -1:
	print(-1)
else:
	M = list(((c, M[c]) for c in M if c < M[c]))
	print(len(M))
	for x in M:
		print(*x)


a = input()
b = input()
n = len(a)
ans = []
match = {}
flag = 0
for i in range(n):
	if a[i] in match:
		if match[a[i]] != b[i]:
			flag = 1
			break
	if b[i] in match:
		if match[b[i]] != a[i]:
			flag = 1
			break
	if a[i] != b[i] and a[i] not in match:
		ans.append(a[i] + ' ' + b[i])
	match[a[i]] = b[i]
	match[b[i]] = a[i]
if flag == 1:
	print(-1)
else:
	print(len(ans))
	for x in ans:
		print(x)


word1 = [str(i) for i in input()]
word2 = [str(i) for i in input()]
backup = word1
backup2 = word2
already = []
final_list = []
bool = True
for x in range(len(word1)):
	if word1 == word2:
		print(0)
		bool = False
		break
	if word1[x] in already:
		continue
	elif word1[x] == word2[x]:
		already.append(word1[x])
	else:
		baseline = word1[x]
		baseline2 = word2[x]
		increment = 0
		for letter in word1:
			if letter == baseline and word2[word1.index(letter)] == baseline2:
				increment += 1
		if increment == word1.count(baseline) and increment == word2.count(baseline2):
			final_list.append([baseline, baseline2])
			already.append(baseline)
			already.append(baseline2)
for y in range(len(final_list)):
	swapping_letters = final_list[y]
	for x in range(len(word1)):
		if backup2[x] == swapping_letters[0]:
			backup2.pop(x)
			backup2.insert(x, swapping_letters[1])
		elif backup2[x] == swapping_letters[1]:
			backup2.pop(x)
			backup2.insert(x, swapping_letters[0])
if bool == True:
	if len(final_list) == 0 or backup2 != backup:
		print(-1)
	else:
		print(len(final_list))
		for item in final_list:
			print(' '.join(item))


def solve(s, t):
	D = {}
	n = len(s)
	for i in range(n):
		if s[i] not in D:
			D[s[i]] = t[i]
		if t[i] not in D:
			D[t[i]] = s[i]
		if t[i] != D[s[i]] or s[i] != D[t[i]]:
			return None
	S = {(min(c, D[c]), max(c, D[c])) for c in D if D[c] != c}
	return S
s = input().rstrip()
t = input().rstrip()
S = solve(s, t)
if S is None:
	print(-1)
else:
	print(len(S))
	for (c1, c2) in S:
		print(c1, c2)


def getindex(ch):
	return ord(ch) - ord('a')
s = input()
t = input()
ch = [chr(ord('a') + i) for i in range(26)]
appear = [0 for i in range(26)]
ok = 1
total = -1
res = []
for i in range(len(s)):
	nows = ch[getindex(s[i])]
	if nows != t[i]:
		total += 1
		res.append((s[i], t[i]))
		(ch[getindex(s[i])], ch[getindex(t[i])]) = (t[i], s[i])
		if appear[getindex(s[i])] or appear[getindex(t[i])]:
			ok = 0
			print(-1)
			break
		appear[getindex(s[i])] = appear[getindex(t[i])] = 1
if ok:
	for i in range(len(s)):
		nows = ch[getindex(s[i])]
		if nows != t[i]:
			ok = 0
			break
	if ok:
		print(total + 1)
		for i in range(total + 1):
			print(res[i][0], res[i][1])
	else:
		print(-1)


s = input()
s2 = input()
a = [set() for i in range(97)]
for i in range(len(s)):
	a[ord(s[i]) - 97].add(ord(s2[i]) - 97)
	a[ord(s2[i]) - 97].add(ord(s[i]) - 97)
if max([len(i) for i in a]) > 1:
	print(-1)
else:
	t = set()
	for i in range(26):
		if a[i] != set():
			o = tuple(sorted([chr(i + 97), chr(list(a[i])[0] + 97)]))
			if o[0] != o[1]:
				t.add(o)
	print(len(t))
	for i in t:
		print(i[0], i[1])


s = input()
t = input()
d1 = {}
d2 = {}
imp = False
for i in range(0, len(t)):
	if d1.get(s[i], '') != '' and d1[s[i]] != t[i]:
		imp = True
		break
	d1[s[i]] = t[i]
	if d2.get(t[i], '') != '' and d2[t[i]] != s[i]:
		imp = True
		break
	d2[t[i]] = s[i]
for e in d1:
	if d1.get(d1[e], '') != '' and d1.get(d1[e], '') != e:
		imp = True
		break
if imp == True:
	print(-1)
else:
	swaps = []
	for e in d1:
		if d1[e] != d2[d1[e]]:
			if not (d1[e], d2[d1[e]]) in swaps and (not (d2[d1[e]], d1[e]) in swaps):
				swaps.append((d1[e], d2[d1[e]]))
	print(len(swaps))
	for e in swaps:
		print(e[0], e[1])


s = input()
t = input()
a = [0] * 123
l = 0
for i in range(len(s)):
	x = ord(s[i])
	y = ord(t[i])
	if s[i] == t[i]:
		if a[x] == x or a[x] == 0:
			a[x] = x
		else:
			print(-1)
			break
	elif s[i] != t[i]:
		if a[x] == 0 and a[y] == 0:
			a[x] = y
			a[y] = x
			l += 1
		elif a[x] != y and a[y] != x:
			print(-1)
			break
else:
	print(l)
	for i in range(len(a)):
		if a[i] != i and a[i] != 0:
			k = a[i]
			print(chr(i), chr(a[i]))
			(a[i], a[k]) = (a[k], a[i])


s = input()
t = input()
d = {}
l = []
ans = 0
for i in range(len(s)):
	if s[i] != t[i] and s[i] not in d and (t[i] not in d) and (s[i] not in l) and (t[i] not in l):
		d[s[i]] = t[i]
		d[t[i]] = s[i]
		ans += 1
	elif s[i] != t[i]:
		if t[i] in d and s[i] != d[t[i]] or (s[i] in d and d[s[i]] != t[i]) or s[i] in l or (t[i] in l):
			ans = -1
			break
	if s[i] == t[i]:
		if s[i] in d:
			ans = -1
			break
		l.append(s[i])
print(ans)
if ans != -1:
	a = []
	for elems in d:
		if d[elems] not in a:
			print(elems, d[elems])
			a.append(elems)


s = input()
t = input()
if s == t:
	print(0)
else:
	p = []
	w = []
	n = len(s)
	k = 0
	for i in range(n):
		if s[i] != t[i]:
			if s[i] in w or t[i] in w:
				print(-1)
				k = -1
				break
			if s[i] < t[i]:
				q = s[i] + t[i]
			else:
				q = t[i] + s[i]
			if not q in p:
				for j in range(k):
					if (s[i] in p[j]) != (t[i] in p[j]):
						print(-1)
						k = -1
						break
				if k > -1:
					k += 1
					p.append(q)
				else:
					break
		else:
			f = True
			for j in range(k):
				if s[i] in p[j]:
					f = False
			if f:
				w.append(s[i])
			else:
				k = -1
				print(-1)
				break
		if k == -1:
			break
	if k > 0:
		print(k)
		for i in range(k):
			s = p[i]
			print(s[0], s[1])


s1 = input()
s2 = input()
n = len(s1)
changes = {}
changesprinted = {}
t = {}
for i in range(n):
	if s1[i] != s2[i]:
		changes[s1[i]] = s2[i]
		if s1[i] not in changes.values():
			changesprinted[s1[i]] = s2[i]
	if not t.get(s2[i]):
		t[s2[i]] = set()
	t[s2[i]].add(s1[i])
b = []
for i in t:
	for k in t[i]:
		b.append(k)
if len(set(b)) < len(b) or len(set(t.keys())) < len(t.keys()):
	print(-1)
	exit()
for i in t:
	if len(t[i]) > 1:
		print(-1)
		exit()
s1_proper = ''
for i in range(n):
	if s1[i] == s2[i]:
		s1_proper += s1[i]
		continue
	for j in changes:
		if j == s2[i]:
			s1_proper += changes[j]
			break
		elif changes[j] == s2[i]:
			s1_proper += j
			break
if s1_proper != s1:
	print(-1)
else:
	print(len(changesprinted))
	for i in changesprinted:
		print(i, changesprinted[i])


s = input()
t = input()
A = dict()
ans = set()
per = 0
for j in range(len(s)):
	if s[j] in A and t[j] in A:
		if A[s[j]] != t[j] or A[t[j]] != s[j]:
			per = 1
			break
	elif t[j] in A and s[j] not in A:
		per = 1
		break
	elif s[j] in A and t[j] not in A:
		per = 1
		break
	else:
		A[s[j]] = t[j]
		A[t[j]] = s[j]
		if s[j] != t[j]:
			if s[j] + t[j] not in ans and t[j] + s[j] not in ans:
				ans.add(s[j] + t[j])
if per != 1:
	print(len(ans))
	for j in ans:
		print(j[0], j[1])
else:
	print(-1)


def solve(s, t):
	n = len(s)
	d = {}
	ok = True
	c = 0
	rez = {}
	for i in range(n):
		if s[i] != t[i]:
			try:
				c1 = d[s[i]]
				if c1 != t[i]:
					ok = False
					break
			except:
				c1 = 0
			try:
				c2 = d[t[i]]
				if c2 != s[i]:
					ok = False
					break
			except:
				c2 = 0
			if c1 == 0 and c2 == 0:
				d[s[i]] = t[i]
				d[t[i]] = s[i]
				rez[s[i]] = t[i]
		else:
			try:
				cc = d[s[i]]
				if cc != t[i]:
					ok = False
					break
			except:
				d[s[i]] = t[i]
	if ok == False:
		print(-1)
	elif rez == {}:
		print(0)
	else:
		print(len(rez))
		for i in rez:
			print(i, rez[i])

def read():
	s = input()
	t = input()
	solve(s, t)
read()


import sys
sys.setrecursionlimit(5000000)

def read(type=int):
	return type(input())

def read_arr(type=int):
	return [type(token) for token in input().split()]
s = read(str)
t = read(str)
mistypes = {}
error = False
for i in range(len(s)):
	if s[i] not in mistypes or mistypes[s[i]] == t[i]:
		mistypes[s[i]] = t[i]
	else:
		error = True
	if t[i] not in mistypes or mistypes[t[i]] == s[i]:
		mistypes[t[i]] = s[i]
	else:
		error = True
if error:
	print(-1)
else:
	m = set()
	for (i, j) in mistypes.items():
		if i < j:
			m.add((i, j))
	print(len(m))
	for tup in m:
		print(tup[0], tup[1])


def solution(s1, s2):
	if s1 == s2:
		return (0, [])
	d = {}
	rep = set()
	ans = []
	for k in range(len(s1)):
		if s1[k] != s2[k]:
			if s1[k] in d and d[s1[k]] != s2[k] or (s2[k] in d and d[s2[k]] != s1[k]):
				return (-1, [])
			if s1[k] in rep or s2[k] in rep:
				return (-1, [])
			if s1[k] not in d:
				ans.append(s1[k] + s2[k])
			d[s1[k]] = s2[k]
			d[s2[k]] = s1[k]
		else:
			if s1[k] in d:
				return (-1, [])
			rep.add(s1[k])
	return (len(ans), ans)
s1 = input()
s2 = input()
(ans, changes) = solution(s1, s2)
if ans < 1:
	print(ans)
else:
	print(ans)
	for k in range(ans):
		print(changes[k][0], changes[k][1])


before = input()
after = input()
length = len(before)
stock = {}
answer = []
for l in range(length):
	if before[l] != after[l] and stock.get(after[l], 0) == 0 and (stock.get(before[l], 0) == 0):
		answer.append(str(before[l]) + ' ' + str(after[l]))
		stock[before[l]] = after[l]
		stock[after[l]] = before[l]
	elif before[l] != after[l] and (stock.get(after[l], 0) == -1 or stock.get(before[l], 0) == -1):
		print(-1)
		break
	elif before[l] != after[l]:
		if stock.get(before[l], 0) != after[l] or stock.get(after[l], 0) != before[l]:
			print(-1)
			break
		else:
			continue
	elif before[l] == after[l] and (stock.get(after[l], 0) not in (0, -1) or stock.get(before[l], 0) not in (0, -1)):
		print(-1)
		break
	else:
		stock[before[l]] = -1
		stock[after[l]] = -1
else:
	anslen = len(answer)
	print(anslen)
	for a in answer:
		print(a)


import sys
read = lambda : sys.stdin.readline().strip()
readi = lambda : map(int, read().split())
from collections import *
original = read()
output = read()
correctMapping = set()
mapping = dict()
for i in range(len(original)):
	key = original[i]
	val = output[i]
	if key in mapping:
		if mapping[key] != val:
			print(-1)
			break
	if val in mapping:
		if mapping[val] != key:
			print(-1)
			break
	if key != val:
		if key in correctMapping or val in correctMapping:
			print(-1)
			break
		mapping[key] = val
		mapping[val] = key
	else:
		correctMapping.add(key)
else:
	n = len(mapping) // 2
	print(n)
	keys = list(mapping.keys())
	for key in keys:
		if key in mapping:
			print(key, mapping[key])
			mapping.pop(mapping[key])
			mapping.pop(key)


s = str(input())
t = str(input())
change = dict()
used = []
b = 0
if len(s) != len(t):
	change[s[0]] = {'a', 'b', 'c'}
for i in range(len(s)):
	if s[i] != t[i]:
		change[s[i]] = set(change.get(s[i], {''}) | {t[i]})
		change[t[i]] = set(change.get(t[i], {''}) | {s[i]})
	else:
		change[s[i]] = set(change.get(s[i], {''}) | {s[i]})
for key in change:
	if len(change[key]) > 2:
		print(-1)
		break
	if change[key] == {'', key}:
		b += 1
else:
	print(int(len(change) / 2 - b / 2))
	for i in change:
		change[i] -= {''}
		for j in change[i]:
			a = j
		if i not in used and i != a:
			print(i, a)
		used += a


s1 = input()
s2 = input()
d = dict()
for i in range(len(s1)):
	if s2[i] != s1[i]:
		res1 = d.get(s1[i], -1)
		res2 = d.get(s2[i], -1)
		if res1 == -1 and res2 == -1 or (res1 == s2[i] and res2 == s1[i]):
			d[s1[i]] = s2[i]
			d[s2[i]] = s1[i]
		else:
			print(-1)
			exit()
	if s2[i] == s1[i]:
		res = d.get(s1[i], -1)
		if res != -1 and res != s1[i]:
			print(-1)
			exit()
		d[s1[i]] = s1[i]
ans = len(d)
for i in d:
	if i == d[i]:
		ans -= 1
print(ans // 2)
used = dict()
for i in d:
	used[i] = 0
for i in d:
	if not used[i] and i != d[i]:
		print(i, d[i])
		used[d[i]] = 1


A = input()
E = input()
c = dict()
N = len(A)
k = 0
pairs = set()
for i in range(N):
	s = (A[i], E[i])
	if A[i] in c or E[i] in c:
		if c.get(A[i], None) != E[i] or c.get(E[i], None) != A[i]:
			print(-1)
			exit()
	elif A[i] != E[i]:
		pairs.add((E[i], A[i]))
		k += 1
	c[A[i]] = E[i]
	c[E[i]] = A[i]
print(k)
for p in pairs:
	print(' '.join(map(str, p)))


def main():
	d = {}
	for (a, b) in zip(input(), input()):
		if d.get(a, b) != b or d.get(b, a) != a:
			print(-1)
			return
		(d[a], d[b]) = (b, a)
	res = ['%s %s' % (a, b) for (a, b) in d.items() if a < b]
	print(len(res))
	print('\n'.join(res))
main()


(s1, s2) = (input(), input())
n = len(s1)
d = dict()
for i in range(n):
	a = s1[i]
	b = s2[i]
	if b < a:
		(a, b) = (b, a)
	if a not in d and b not in d:
		d[a] = b
		d[b] = a
	elif a in d and b not in d or (a not in d and b in d):
		print(-1)
		break
	elif d[a] != b or d[b] != a:
		print(-1)
		break
else:
	k = []
	for i in d.items():
		if i[0] < i[1]:
			k.append('{} {}'.format(i[0], i[1]))
	print(len(k))
	print(*k, sep='\n')


right_string = input()
in_string = input()
pairs = []
from_str = ''
to_str = ''
for i in range(len(in_string)):
	if in_string[i] != right_string[i]:
		if in_string[i] not in from_str:
			from_str += in_string[i]
			to_str += right_string[i]
for i in range(len(from_str)):
	if from_str[i] in to_str:
		if from_str[to_str.find(from_str[i])] != to_str[i]:
			print(-1)
			exit(0)
print()
if in_string == right_string.translate(str.maketrans(to_str, from_str)) and right_string == in_string.translate(str.maketrans(from_str, to_str)):
	for i in range(len(from_str)):
		if not ([to_str[i], from_str[i]] in pairs or [from_str[i], to_str[i]] in pairs):
			pairs.append([to_str[i], from_str[i]])
	print(len(pairs))
	for i in pairs:
		print(' '.join(i))
else:
	print(-1)


a = input()
b = input()
d = {}
for (i, x) in enumerate(a):
	y = b[i]
	if d.get(x) == None:
		d[x] = []
	if d.get(y) == None:
		d[y] = []
	d[x].append(y)
	d[y].append(x)
res = 0
k = 0
for (i, x) in enumerate(d):
	if len(set(d[x])) > 1:
		print(-1)
		res = 1
		break
	if x != d[x][0]:
		k += 1
di = {}
if res == 0:
	print(k // 2)
	for (i, x) in enumerate(d):
		if x != d[x][0]:
			if di.get(d[x][0]) == None:
				print(x, *set(d[x]))
				di[x] = 0


s = input()
t = input()
(w1, w2) = (set(), set())
for i in range(len(s)):
	(l1, l2) = (min(s[i], t[i]), max(s[i], t[i]))
	if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1:
		print(-1)
		exit()
	else:
		w2.add(s[i])
		w2.add(t[i])
		w1.add((l1, l2))
result = [elem for elem in w1 if elem[0] != elem[1]]
print(len(result))
for elem in result:
	print(*elem)


s = input()
t = input()
n = len(s)
d = ['#'] * 26
k = 0
for i in range(n):
	if d[ord(s[i]) - 97] == '#' and d[ord(t[i]) - 97] == '#':
		d[ord(s[i]) - 97] = t[i]
		d[ord(t[i]) - 97] = s[i]
		if s[i] != t[i]:
			k += 1
	elif d[ord(s[i]) - 97] != t[i] or d[ord(t[i]) - 97] != s[i]:
		print(-1)
		exit()
print(k)
for i in range(26):
	if d[i] != '#' and d[i] != chr(97 + i):
		print(chr(97 + i), d[i])
		d[ord(d[i]) - 97] = '#'


sa = input()
sb = input()
ma = {}
flg = 0
for (x, y) in zip(sa, sb):
	if ma.get(x) != None:
		if ma[x] != y:
			flg = 1
			break
	elif ma.get(y) != None:
		if ma[y] != x:
			flg = 1
			break
	else:
		ma[x] = y
		ma[y] = x
if flg:
	print(-1)
else:
	cnt = 0
	for (x, y) in ma.items():
		if ord(x) < ord(y):
			cnt += 1
	print(cnt)
	for (x, y) in ma.items():
		if ord(x) < ord(y):
			print(x, y)


(s, t) = (input(), input())
dict = {}
for i in range(len(s)):
	if s[i] in dict:
		if dict[s[i]] is not t[i]:
			print(-1)
			exit()
	else:
		dict[s[i]] = t[i]
	if t[i] in dict:
		if dict[t[i]] is not s[i]:
			print(-1)
			exit()
	else:
		dict[t[i]] = s[i]
dic = {}
res = {}
for (key, val) in dict.items():
	if key in dic or val in dic or key == val:
		continue
	dic[key] = 'exist'
	dic[val] = 'exist'
	res[key] = val
print(len(res))
for (key, val) in res.items():
	print(key, val)


dict = {}
l = []
o = input()
s = input()
for i in range(len(o)):
	if o[i] == s[i]:
		if o[i] not in l:
			if o[i] not in dict.keys() and o[i] not in dict.values():
				l.append(o[i])
			else:
				print('-1')
				exit()
	elif o[i] in l or s[i] in l:
		print('-1')
		exit()
	elif o[i] in dict.keys():
		if dict[o[i]] != s[i]:
			print('-1')
			exit()
	elif s[i] in dict.keys():
		if dict[s[i]] != o[i]:
			print('-1')
			exit()
	elif s[i] in dict.values() or o[i] in dict.values():
		print('-1')
		exit()
	else:
		dict[o[i]] = s[i]
print(len(dict))
for c in dict.keys():
	print(c, dict[c])


a = input()
b = input()
d = {}
for i in range(len(a)):
	if d.get(a[i]) and d[a[i]] != b[i] or (d.get(b[i]) and d[b[i]] != a[i]):
		print('-1')
		break
	elif not d.get(a[i]) and (not d.get(b[i])):
		d[a[i]] = b[i]
		d[b[i]] = a[i]
else:
	ans = {}
	for x in d:
		ans[x] = d[x]
	for x in d:
		if ans.get(x) and ans.get(d[x]):
			ans.pop(x)
	print(len(ans))
	for x in ans:
		print(x, d[x])


expected = input()
actual = input()
pairs = {}
flag = True
num = 0
for i in range(len(actual)):
	if expected[i] not in pairs.keys():
		if actual[i] in pairs.values():
			flag = False
		pairs[expected[i]] = actual[i]
		if actual[i] not in pairs.keys():
			pass
		elif pairs[actual[i]] != expected[i]:
			flag = False
		elif expected[i] == actual[i]:
			num += 1
		elif pairs[actual[i]] == expected[i]:
			del pairs[expected[i]]
	elif pairs[expected[i]] != actual[i]:
		flag = False
	if not flag:
		print('-1')
		break
if flag:
	print(len(pairs) - num)
	for (k, v) in pairs.items():
		if k != v:
			print(k, v)


s = input()
t = input()
sw = [''] * 26
d = ord('a')
m = 0
r = 0
for i in range(len(s)):
	k = ord(s[i]) - d
	l = ord(t[i]) - d
	if s[i] == t[i]:
		if sw[k] == '':
			sw[k] = s[i]
		elif sw[k] != s[i]:
			r = -1
			break
	elif sw[k] == '' and sw[l] == '':
		sw[k] = s[i] + t[i]
		sw[l] = t[i] + s[i] + ' '
		m += 1
	elif not (sw[k][:2] == s[i] + t[i] and sw[l][:2] == t[i] + s[i]):
		r = -1
		break
if r == -1:
	print(-1)
else:
	print(m)
	for i in range(26):
		if len(sw[i]) == 2:
			print(sw[i][0] + ' ' + sw[i][1])


string1 = input()
string2 = input()
map = dict()
for i in range(len(string1)):
	if string1[i] != string2[i] and string1[i] not in map and (string2[i] not in map):
		map[string1[i]] = string2[i]
		map[string2[i]] = string1[i]
tmp = ''
for c in string2:
	if c in map:
		tmp += map[c]
	else:
		tmp += c
printed = set()
if string1 == tmp:
	print(len(map) // 2)
	for v in map:
		if v not in printed and map[v] not in printed:
			print(v, map[v])
			printed.add(v)
			printed.add(map[v])
else:
	print(-1)


a = input()
b = input()
symbols = {}
pairs = []
for i in range(len(a)):
	if a[i] in symbols:
		if symbols[a[i]] != b[i]:
			print('-1')
			break
	elif b[i] in symbols:
		if symbols[b[i]] != a[i]:
			print('-1')
			break
	else:
		symbols[a[i]] = b[i]
		symbols[b[i]] = a[i]
		if a[i] != b[i]:
			pairs.append((a[i], b[i]))
else:
	print(len(pairs))
	for elem in pairs:
		print(elem[0], elem[1])