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: interview

Starter code:

Solutions:
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])

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
    else:
        if (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
    else:
        if ord(used[i]) < i:
            ans.append([used[i], chr(i)])
print(len(ans))
for elem in ans:
    print(elem[0], elem[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])


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()

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()


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)

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])
            
            


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)
            return
    if s2[i] == s1[i]:
        res = d.get(s1[i], -1)
        if res != -1 and res != s1[i]:
            print(-1)
            return
        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

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)


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 = 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)
        


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])


correct = input()
incorrect = input()

other = dict()#to correct from incorrect

for i in range(ord('a'), ord('z') + 1):
    other[chr(i)] = chr(i)
    #print(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)



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])

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])


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')

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)

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])


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])

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 list(d.items()):
        if i[0] < i[1]:
            ans.append((i[0], i[1]))
    print(len(ans))
    for elem in ans:
        print(*elem)


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])


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
        else:
            if 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()

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
    else:
        if a in d and d[a] != a:
            f = False
            break
        else:
            d[a] = a
if f:
    a = []
    for i in list(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)


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])

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)