You have an image file of size $2 \times 2$, consisting of $4$ pixels. Each pixel can have one of $26$ different colors, denoted by lowercase Latin letters.

You want to recolor some of the pixels of the image so that all $4$ pixels have the same color. In one move, you can choose no more than two pixels of the same color and paint them into some other color (if you choose two pixels, both should be painted into the same color).

What is the minimum number of moves you have to make in order to fulfill your goal?


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

Each test case consists of two lines. Each of these lines contains two lowercase letters of Latin alphabet without any separators, denoting a row of pixels in the image.


-----Output-----

For each test case, print one integer — the minimum number of moves you have to make so that all $4$ pixels of the image have the same color.


-----Examples-----

Input
5
rb
br
cc
wb
aa
aa
ab
cd
yy
xx
Output
1
2
0
3
1


-----Note-----

Let's analyze the test cases of the example.

In the first test case, you can paint the bottom left pixel and the top right pixel (which share the same color) into the color r, so all pixels have this color.

In the second test case, two moves are enough:

paint both top pixels, which have the same color c, into the color b;

paint the bottom left pixel into the color b.

In the third test case, all pixels already have the same color.

In the fourth test case, you may leave any of the pixels unchanged, and paint all three other pixels into the color of that pixel in three moves.

In the fifth test case, you can paint both top pixels into the color x.

Difficulty: EASY
Tags: Implementation

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
import sys

def solve():
	inp = sys.stdin.readline
	s = inp().strip() + inp().strip()
	c = [s.count(s[i]) for i in range(4)]
	m = max(c)
	if m == 4:
		print(0)
	elif m == 3:
		print(1)
	elif m == 2:
		if min(c) == 1:
			print(2)
		else:
			print(1)
	elif m == 1:
		print(3)

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


t = int(input())
for i in range(t):
	s = ''
	s += input()
	s += input()
	print(len(set(list(s))) - 1)


for i in range(int(input())):
	r1 = input()
	r2 = input()
	a = r1[0]
	c = r2[0]
	b = r1[1]
	d = r2[1]
	set = {a, b, c, d}
	print(len(set) - 1)


for _ in range(int(input())):
	g = set(''.join((input() for _ in range(2))))
	print(len(g) - 1)


def solution(ab, cd):
	d = {}
	d[ab[0]] = d.get(ab[0], 0) + 1
	d[ab[1]] = d.get(ab[1], 0) + 1
	d[cd[0]] = d.get(cd[0], 0) + 1
	d[cd[1]] = d.get(cd[1], 0) + 1
	return len(d.keys()) - 1
t = int(input())
while t:
	ab = input()
	cd = input()
	print(solution(ab, cd))
	t -= 1


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	a = a + b
	b = list(set(list(a)))
	c = []
	for i in range(len(b)):
		d = 0
		for j in range(len(a)):
			if b[i] == a[j]:
				d += 1
		c.append(d)
	c.sort()
	if c == [4]:
		print(0)
	if c == [2, 2]:
		print(1)
	if c == [1, 3]:
		print(1)
	if c == [1, 1, 2]:
		print(2)
	if c == [1, 1, 1, 1]:
		print(3)


t = int(input())
for _ in range(t):
	a = list(input())
	b = list(input())
	s = set([a[0], b[0], a[1], b[1]])
	l = len(s)
	print(len(s) - 1)


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

def intRd():
	return int(input())

def lstStrRd():
	return list(input())
for _ in range(int(input())):
	a = []
	a += lstStrRd()
	a += lstStrRd()
	print(len(set(a)) - 1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip()
	k = input().strip()
	d = {}
	for i in s:
		d[i] = d.get(i, 0) + 1
	for i in k:
		d[i] = d.get(i, 0) + 1
	s = 0
	print(len(d.keys()) - 1)


for _ in range(int(input())):
	li = list(input()) + list(input())
	s = set(li)
	if len(s) == 4:
		print(3)
	elif len(s) == 3:
		print(2)
	elif len(s) == 2:
		print(1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	s = input()
	s = s + input()
	s = set(s)
	n = len(s)
	print(n - 1)


for _ in range(int(input())):
	a = list(input())
	b = list(input())
	a.extend(b)
	if len(set(a)) == 1:
		print(0)
	elif len(set(a)) == 2:
		print(1)
	elif len(set(a)) == 3:
		print(2)
	else:
		print(3)


t = int(input())
while t > 0:
	x = [i for i in input()]
	a = [i for i in input()]
	x.extend(a)
	s = set(x)
	if len(s) == 2:
		print('1')
	elif len(s) == 1:
		print('0')
	elif len(s) == 3:
		print(2)
	elif len(s) == 4:
		print('3')
	t -= 1


for _ in range(int(input())):
	s = input()
	s += input()
	n = len(set(s))
	if n == 1:
		print(0)
	elif n == 2:
		print(1)
	elif n == 3:
		print(2)
	else:
		print(3)


testCases = int(input())
for i in range(testCases):
	line1 = input()
	line2 = input()
	all_chars = set(line1 + line2)
	print(len(all_chars) - 1)


for _ in range(int(input())):
	x = input()
	l2 = input()
	(a, b) = (x[0], x[1])
	(c, d) = (l2[0], l2[1])
	s = set([a, b, c, d])
	if a == b and a == c and (a == d):
		print(0)
	elif len(s) == 2:
		print(1)
	elif len(s) == 3:
		print(2)
	elif len(s) == 4:
		print(3)


def solve():
	image = []
	image.extend(list(input()))
	image.extend(list(input()))
	iset = set(image)
	return len(iset) - 1
for tc in range(int(input())):
	print(solve())


def inp():
	return int(input())

def strng():
	return input().strip()

def jn(x, l):
	return x.join(map(str, l))

def strl():
	return list(input().strip())

def mul():
	return map(int, input().strip().split())

def mulf():
	return map(float, input().strip().split())

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

def ceil(x):
	return int(x) if x == int(x) else int(x) + 1

def ceildiv(x, d):
	return x // d if x % d == 0 else x // d + 1
for i in range(inp()):
	lst = strl()
	l1 = strl()
	l = lst + l1
	s = set(l)
	length_l = len(s)
	if length_l == 4:
		print(3)
	elif length_l == 3:
		print(2)
	elif length_l == 2:
		print(1)
	else:
		print(0)


for k in range(int(input())):
	a = input()
	c = input()
	b = a[1]
	d = c[1]
	a = a[0]
	c = c[0]
	n = [a, b, c, d]
	n = set(n)
	r = len(n)
	if r == 1:
		print('0')
	elif r == 2:
		print('1')
	elif r == 3:
		print('2')
	else:
		print('3')


from collections import defaultdict
res = []
for _ in range(int(input())):
	d = defaultdict(int)
	for l in list(input()):
		d[l] += 1
	for l in list(input()):
		d[l] += 1
	res.append(len(d) - 1)
for r in res:
	print(r)


x = int(input())
for i in range(x):
	arr = []
	r1 = input()
	r2 = input()
	for i in r1:
		if i not in arr:
			arr.append(i)
	for i in r2:
		if i not in arr:
			arr.append(i)
	print(len(arr) - 1)


t = int(input())
for i in range(t):
	s = ''
	s = s + input()
	s = s + input()
	dic = {}
	for j in s:
		if j in dic:
			dic[j] += 1
		else:
			dic[j] = 1
	lis = sorted(list(dic.values()))
	l = len(lis)
	if l == 4:
		print(3)
	elif l == 1:
		print(0)
	elif l == 2:
		print(1)
	elif l == 3:
		print(2)


class Solution:

	def solve(self, matrix):
		s = [matrix[0][0], matrix[0][1], matrix[1][0], matrix[1][1]]
		s = set(s)
		if len(s) == 4:
			return 3
		if len(s) == 3:
			return 2
		if len(s) == 2:
			return 1
		if len(s) == 1:
			return 0

def main():
	t = int(input())
	sol = Solution()
	ip = []
	for _ in range(t):
		ip.append([input(), input()])
	s = []
	for x in ip:
		s.append(sol.solve(x))
	for x in s:
		print(x)
main()


import sys
import collections
from math import ceil, gcd, sqrt, log
import bisect
INF = float('inf')
mod = 1000000007

def solve():
	s = input()
	s2 = input()
	ok = s + s2
	net = list(set(ok))
	if len(net) == 1:
		print(0)
	elif len(net) == 2:
		print(1)
	elif len(net) == 3:
		print(2)
	else:
		print(3)
t = int(input())
while t != 0:
	solve()
	t -= 1


n = int(input())
for i in range(n):
	a = input()
	b = input()
	d = a + b
	d = set(d)
	print(len(d) - 1)


t = int(input())
for i in range(t):
	l = input()
	l1 = input()
	l3 = []
	for i in l:
		if i not in l3:
			l3.append(i)
	for j in l1:
		if j not in l3:
			l3.append(j)
	if len(l3) == 1:
		print(0)
	elif len(l3) == 2:
		print(1)
	elif len(l3) == 4:
		print(3)
	elif len(l3) == 3:
		print(2)


for i in range(int(input())):
	a = input()
	c = input()
	s = set()
	s.add(a[0])
	s.add(a[1])
	s.add(c[0])
	s.add(c[1])
	if len(s) == 4:
		print(3)
	elif len(s) == 3:
		print(2)
	elif len(s) == 2:
		print(1)
	else:
		print(0)


import sys
input = sys.stdin.readline

def int_num():
	return int(input())

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

def str_list():
	s = input()
	return list(s[:len(s) - 1])

def instr():
	return input().strip()

def invr():
	return map(int, input().split())

def solve():
	s1 = instr()
	s2 = instr()
	st = set(s1 + s2)
	ans = len(st) - 1
	print(ans)

def main():
	t = int_num()
	while t:
		solve()
		t -= 1
	return
main()


for _ in range(int(input())):
	s = {*input()} | {*input()}
	print(len(s) - 1)


t = int(input())
for i in range(t):
	str1 = input()
	str2 = input()
	a = str1[0]
	b = str1[1]
	c = str2[0]
	d = str2[1]
	lst = []
	count = 0
	lst.append(a)
	lst.append(b)
	lst.append(c)
	lst.append(d)
	for i in range(4):
		a = lst[i]
		for j in range(i + 1, 4):
			b = lst[j]
			if a == b:
				count = count + 1
			else:
				pass
	if count == 0:
		print(3)
	elif count == 1:
		print(2)
	elif count == 2:
		print(1)
	elif count == 3:
		print(1)
	elif count == 6:
		print(0)
	else:
		pass


t = int(input())
for _ in range(t):
	(a, b) = input()
	(c, d) = input()
	l = [a, b, c, d]
	if len(set(l)) == 1:
		print(0)
	else:
		print(len(set(l)) - 1)


kol = int(input())
for j in range(0, kol):
	s1 = input()
	s2 = input()
	d = {s1[0]: 0, s1[1]: 0, s2[0]: 0, s2[1]: 0}
	d[s1[0]] = d[s1[0]] + 1
	d[s1[1]] = d[s1[1]] + 1
	d[s2[0]] = d[s2[0]] + 1
	d[s2[1]] = d[s2[1]] + 1
	l = list(d.values())
	k_max = max(l)
	count = 0
	for (i, c) in enumerate(d.keys()):
		if d[c] == k_max:
			count = count + 1
	if k_max == 4:
		print(0)
	if k_max == 3:
		print(1)
	if k_max == 2 and count == 1:
		print(2)
	if k_max == 2 and count == 2:
		print(1)
	if k_max == 1:
		print(3)


for _ in range(int(input())):
	pixels = set(input() + input())
	print({1: 0, 2: 1, 3: 2, 4: 3}[len(pixels)])


t = int(input())
arr = []
for i in range(t):
	a = input()
	b = input()
	a0 = a[0]
	a1 = a[1]
	a2 = b[0]
	a3 = b[1]
	if a0 == a1 and a1 == a2 and (a2 == a3) and (a3 == a1):
		print(0)
	else:
		l = []
		l.append(a0)
		l.append(a1)
		l.append(a2)
		l.append(a3)
		m = dict()
		for i in range(4):
			if l[i] not in m:
				m[l[i]] = 0
			else:
				pass
		count = len(m)
		if count == 2:
			print(1)
		elif count == 3:
			print(2)
		else:
			print(3)


I = input
for _ in [0] * int(I()):
	s = I() + I()
	print(sum((x + 1 >> 1 for x in sorted(map(s.count, {*s}))[:-1])))


T = int(input())
l = []
for i in range(T):
	s1 = input()
	s2 = input()
	s3 = s1 + s2
	l.append(s3)
for i in l:
	s = set(i)
	c = len(s) - 1
	print(c)


t = int(input())
i = 0
while i < t:
	stringinput1 = input()
	stringinput2 = input()
	a = stringinput1[0]
	b = stringinput1[1]
	c = stringinput2[0]
	d = stringinput2[1]
	setofcolours = {a, b, c, d}
	print(len(setofcolours) - 1)
	i += 1


n = int(input())
for i in range(n):
	s = list(input())
	p = list(input())
	q = s + p
	r = list(set(q))
	w = []
	for j in r:
		w.append(q.count(j))
	print(len(w) - 1)


for i in range(int(input())):
	a = list(set([x for x in input()]))
	b = list(set([x for x in input()]))
	if len(set(a + b)) == 1:
		print(0)
	elif len(set(a + b)) == 2:
		print(1)
	elif len(set(a + b)) == 3:
		print(2)
	else:
		print(3)


test_case = int(input())
for i in range(test_case):
	l1 = list(input())
	l2 = list(input())
	l = l1[:]
	l.extend(l2)
	cc1 = l.count(l[0])
	cc2 = l.count(l[1])
	cc3 = l.count(l[2])
	cc4 = l.count(l[3])
	if cc1 == 1 and cc2 == 1 and (cc3 == 1) and (cc4 == 1):
		print(3)
	elif cc1 == 2 and cc2 == 2 and (cc3 == 2):
		print(1)
	elif cc1 == 2 and cc2 == 2 and (cc3 != 2) or (cc1 == 2 and cc2 != 2 and (cc3 == 2)) or (cc1 == 2 and cc2 != 2 and (cc4 == 2)) or (cc1 != 2 and cc2 == 2 and (cc3 == 2)) or (cc1 != 2 and cc2 == 2 and (cc4 == 2)) or (cc1 != 2 and cc3 == 2 and (cc4 == 2)):
		print(2)
	elif cc1 == 3 or cc2 == 3:
		print(1)
	elif cc1 == 4:
		print(0)


for i in range(int(input())):
	s = input() + input()
	c = {s[0]: 0, s[1]: 0, s[2]: 0, s[3]: 0}
	for j in s:
		c[j] += 1
	comb = sorted(c.values())
	if comb == [1, 1, 1, 1]:
		print(3)
	if comb == [1, 1, 2]:
		print(2)
	if comb == [2, 2]:
		print(1)
	if comb == [4]:
		print(0)
	if comb == [1, 3]:
		print(1)


def main():
	t = int(input())
	for i in range(t):
		s1 = input()
		s2 = input()
		s = s1 + s2
		m = set(s)
		print(len(m) - 1)
main()


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	s = s1 + s2
	l = []
	for i in range(4):
		l.append(s[i])
	print(len(set(l)) - 1)


n = int(input())
for i in range(n):
	a = input()
	b = input()
	count = 0
	c = a + b
	d = set(list(c))
	print(len(d) - 1)


g = int(input())
for i in range(g):
	m = input()
	n = input()
	d = m + n
	e = set(list(d))
	print(len(e) - 1)


for _ in range(int(input())):
	a = list(input())
	b = list(input())
	l = []
	j = ''
	for i in a:
		l.append(i)
	for i in b:
		l.append(i)
		x = 0
		y = 0
	for i in l:
		if l.count(i) == 4:
			y = 0
			break
		if l.count(i) == 3:
			y = 1
			break
		if l.count(i) == 2 and x == 0:
			x = 2
			j = i
			continue
		if l.count(i) == 2 and x != 0 and (i != j):
			x = 0
			y = 1
			break
		if l.count(i) == 1:
			y += 1
			continue
	if y == 4:
		print(3)
	else:
		print(y)


t = int(input())
for _ in range(t):
	l1 = input()
	l2 = input()
	m = list(l1) + list(l2)
	m = set(m)
	n = len(m)
	if n == 2:
		print(1)
	elif n == 3:
		print(2)
	elif n == 4:
		print(3)
	else:
		print(0)


def solve():
	t1 = str(input())
	t2 = str(input())
	t = t1 + t2
	a = [t[0], t[1], t[2], t[3]]
	a1 = a.count(a[0])
	a2 = a.count(a[1])
	a3 = a.count(a[2])
	a4 = a.count(a[3])
	result = a1 + a2 + a3 + a4
	if result == 16:
		print(0)
	elif result == 10 or result == 8:
		print(1)
	elif result == 6:
		print(2)
	elif result == 4:
		print(3)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	d = {}
	for i in s1:
		try:
			d[i] += 1
		except:
			d[i] = 1
	for i in s2:
		try:
			d[i] += 1
		except:
			d[i] = 1
	print(len(d) - 1)


res = []
for _ in range(int(input())):
	st = set()
	a = input()
	c = input()
	st.add(a[0])
	st.add(a[1])
	st.add(c[0])
	st.add(c[1])
	res.append(len(st) - 1)
print(*res, sep='\n')


t = int(input())
for i in range(t):
	y = input()
	z = input()
	a = [y[0], y[1], z[0], z[1]]
	a.sort()
	c = 0
	if a[0] == a[1]:
		c += 1
	if a[1] == a[2]:
		c += 1
	if a[2] == a[3]:
		c += 1
	if c == 0:
		print(3)
	elif c == 1:
		print(2)
	elif c == 2:
		print(1)
	elif c == 3:
		print(0)


t = int(input())
for j in range(t):
	a = ''
	for _ in range(2):
		a += input()
	print(len(set(a)) - 1)


for _ in range(int(input())):
	t = set()
	a = list(input())
	a.extend(list(input()))
	t = set(a)
	if len(t) == 1:
		print(0)
	elif len(t) == 2:
		print(1)
	elif len(t) == 3:
		print(2)
	elif len(t) == 4:
		print(3)


from collections import Counter
length = int(input())
for _ in range(length):
	graph = ''
	graph += input()
	graph += input()
	counter = Counter(graph)
	print(len(counter) - 1)


for _ in range(int(input())):
	a = input()
	b = input()
	s = set()
	for i in a:
		s.add(i)
	for i in b:
		s.add(i)
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		print(1)
	elif len(s) == 3:
		print(2)
	else:
		print(3)


import sys
input = sys.stdin.readline

def print(*args, end='\n', sep=' ') -> None:
	sys.stdout.write(sep.join(map(str, args)) + end)

def Solve():
	for t in range(int(input())):
		a = input().strip('\n')
		b = input().strip('\n')
		print(len(set(a + b)) - 1)
Solve()


from collections import Counter

def main():
	t = int(input())
	for t in range(1, t + 1):
		s = ''
		s += input()
		s += input()
		c = Counter(s)
		print(len(c) - 1)
main()


def main():
	a = list(input())
	b = list(input())
	a += b
	if len(set(a)) == 1:
		return 0
	l = len(set(a))
	if l == 4:
		return 3
	freq = {}
	for s in a:
		if s not in freq:
			freq[s] = 0
		freq[s] += 1
	if l == 3:
		return 2
	return 1
for _ in range(int(input())):
	print(main())


import math
l = []
unique_l = []
for _ in range(int(input())):
	t = input()
	p = input()
	for tt in t:
		l.append(tt)
	for pp in p:
		l.append(pp)
	for ll in l:
		if ll not in unique_l:
			unique_l.append(ll)
	if len(unique_l) == 4:
		print(3)
	elif len(unique_l) == 1:
		print(0)
	else:
		print(math.ceil(len(unique_l) / 2))
	l = []
	unique_l = []


for x in range(int(input())):
	a = input()
	b = input()
	c = a + b
	s = set(c)
	print(len(s) - 1)


for kg in range(int(input())):
	freq = [0] * 26
	s = input()
	t = input()
	s += t
	for i in range(len(s)):
		freq[ord(s[i]) - ord('a')] = 1
	summ = sum(freq)
	dict = {1: 0, 2: 1, 3: 2, 4: 3}
	print(dict[summ])


t = int(input())
for t1 in range(t):
	up = input()
	down = input()
	(a, b) = (up[0], up[1])
	(c, d) = (down[0], down[1])
	s = set([a, b, c, d])
	if len(s) == 4:
		print(3)
	elif len(s) == 3:
		print(2)
	elif len(s) == 2:
		print(1)
	elif len(s) == 1:
		print(0)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	st = a + b
	dct = {}
	for j in st:
		if j not in dct:
			dct[j] = 1
		else:
			dct[j] += 1
	if len(dct) == 1:
		res = 0
	elif len(dct) == 2:
		res = 1
	elif len(dct) == 3:
		res = 2
	else:
		res = 3
	print(res)


for _ in range(int(input())):
	aa = input()
	bb = input()
	add = aa + bb
	s = set(add)
	z = len(s)
	if z == 4:
		print(3)
	elif z == 3:
		print(2)
	elif z == 2:
		print(1)
	else:
		print(0)


from collections import Counter

def solve(string):
	freqs = Counter(string)
	return len(freqs) - 1
t = int(input())
for _ in range(t):
	upper = input()
	lower = input()
	print(solve(upper + lower))


for i in range(int(input())):
	n = input()
	m = input()
	if len(set(n + m)) == 1:
		print(0)
	elif len(set(n + m)) == 2:
		print(1)
	elif len(set(n + m)) == 4:
		print(3)
	else:
		print(2)


for _ in range(int(input())):
	s1 = input()
	s2 = input()
	s = s1 + s2
	b = set(s)
	if len(b) == 4:
		print(3)
	elif len(b) == 1:
		print(0)
	elif len(b) == 2:
		print(1)
	else:
		print(2)


t = int(input())
while t:
	t -= 1
	a = input()
	b = input()
	w = a[0]
	x = a[1]
	y = b[0]
	z = b[1]
	x1 = set()
	x1.add(x)
	x1.add(y)
	x1.add(w)
	x1.add(z)
	if w == x and x == y and (y == z):
		print(0)
	elif len(x1) == 4:
		print(3)
	elif len(x1) == 2:
		print(1)
	elif len(x1) == 3:
		print(2)


count = int(input())
for times in range(count):
	arr = list(input()) + list(input())
	value = len(set(arr))
	if value == 4:
		print(3)
	elif value == 3:
		print(2)
	elif value == 2:
		print(1)
	else:
		print(0)


def mi():
	return map(int, input().split())

def li():
	return list(mi())

def si():
	return str(input())

def ni():
	return int(input())

def yn(ans):
	if ans:
		print('YES')
	else:
		print('NO')
for T in range(int(input())):
	s = ''
	s += str(input()) + str(input())
	print(len(set(s)) - 1)


t = int(input())
for i in range(t):
	colors = set()
	for j in range(2):
		(q, w) = [x for x in list(input())]
		colors.add(q)
		colors.add(w)
	print(len(colors) - 1)


n = int(input())
for i in range(n):
	x = input()
	y = input()
	z = []
	for i in x:
		z.append(i)
	for i in y:
		z.append(i)
	z = set(z)
	print(len(z) - 1)


import collections
list1 = []
num = 0
for _ in range(int(input())):
	list1 = []
	a = input()
	c = input()
	list1.append(a[0])
	list1.append(a[1])
	list1.append(c[0])
	list1.append(c[1])
	dict1 = list(collections.Counter(list1).keys())
	print(len(dict1) - 1)


cases = int(input())
IMG_SIZE = 2
for _ in range(cases):
	colors = set()
	for i in range(IMG_SIZE):
		for pixel in input():
			colors.add(pixel)
	print(len(colors) - 1)


for i in range(int(input())):
	a = []
	a += input()
	a += input()
	a = set(a)
	print(len(a) - 1)


t = int(input())
result = []
for i in range(t):
	up = input()
	down = input()
	mnozh = set(up + down)
	if len(mnozh) == 4:
		result.append(3)
		continue
	if len(mnozh) == 1:
		result.append(0)
		continue
	if len(mnozh) == 2:
		result.append(1)
		continue
	if len(mnozh) == 3:
		result.append(2)
		continue
list(map(print, result))


for _ in range(int(input())):
	s = input()
	k = input()
	dict = {}
	for i in s:
		try:
			dict[i] += 1
		except:
			dict[i] = 1
	for i in k:
		try:
			dict[i] += 1
		except:
			dict[i] = 1
	if len(dict) == 4:
		print(3)
	elif len(dict) == 3:
		print(2)
	elif len(dict) == 2:
		print(1)
	else:
		print(0)


t = int(input())
for i in range(t):
	s = input()
	p = input()
	f = s + p
	if len(set(f)) == 1:
		print(0)
	elif len(set(f)) == 2:
		print(1)
	elif len(set(f)) == 3:
		print(2)
	else:
		print(3)


def same_colour():
	n = int(input())
	lst_ans = []
	for i in range(n):
		lst_1 = list(input())
		lst_2 = list(input())
		lst_3 = lst_1 + lst_2
		set_1 = set(lst_3)
		k = len(set_1)
		if k == 1:
			lst_ans.append(0)
		if k == 2:
			lst_ans.append(1)
		if k == 3:
			lst_ans.append(2)
		if k == 4:
			lst_ans.append(3)
	for j in lst_ans:
		print(j)
same_colour()


a = int(input())
for i in range(a):
	s1 = input()
	s2 = input()
	s = s1 + s2
	s = list(s)
	un = list(set(s))
	if len(un) == 2:
		print('1')
	if len(un) == 1:
		print('0')
	if len(un) == 3:
		print('2')
	if len(un) == 4:
		print('3')


T = int(input())
for t in range(0, T):
	s1 = input()
	s2 = input()
	hm = [0 for i in range(0, 26)]
	for i in range(0, 2):
		hm[ord(s1[i]) - 97] += 1
		hm[ord(s2[i]) - 97] += 1
	if hm.count(0) + hm.count(1) == 26:
		print(3)
	elif hm.count(2) == 1:
		print(2)
	elif hm.count(2) == 2 or hm.count(3) == 1:
		print(1)
	elif hm.count(4) == 1:
		print(0)


for i in range(int(input())):
	s11 = input()
	s22 = input()
	s = set(s11 + s22)
	print(len(s) - 1)


n = int(input())
arr = set()
for i in range(n):
	x = input()
	y = input()
	for (z, j) in (x, y):
		arr.add(z)
		arr.add(j)
	print(len(arr) - 1)
	arr = set()


def unique_char(para):
	lst2 = []
	for a in range(4):
		if not para[a] in lst2:
			lst2.append(para[a])
	return len(lst2)

def result(para2):
	if para2 == 1:
		return print(0)
	elif para2 == 2:
		return print(1)
	elif para2 == 3:
		return print(2)
	elif para2 == 4:
		return print(3)
t = int(input())
for i in range(t):
	l1 = list(input())
	l2 = list(input())
	lst = l1 + l2
	u = unique_char(lst)
	result(u)


for _ in range(int(input())):
	letters = set()
	for i in range(2):
		letters.update(list(input()))
	print(len(letters) - 1)


t = int(input())
for _ in range(t):
	str1 = input()
	str2 = input()
	list1 = set(list(str1 + str2))
	print(len(list1) - 1)


import sys
LI = lambda : list(map(str, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
n = II()
for _ in range(n):
	a = SI()
	b = SI()
	c = []
	c.append(a[1])
	c.append(a[0])
	c.append(b[1])
	c.append(b[0])
	c = set(c)
	uniqueValues = len(c)
	if uniqueValues == 1:
		print(0)
	elif uniqueValues == 2:
		print(1)
	elif uniqueValues == 3:
		print(2)
	else:
		print(3)


t = int(input())
for ii in range(t):
	a = input()
	b = input()
	cnt = 0
	aa = ''
	for i in a:
		if i not in aa:
			cnt += 1
			aa += i
	for f in b:
		if f not in aa:
			cnt += 1
			aa += f
	print(cnt - 1)


for _ in range(int(input())):
	a = input()
	b = input()
	c = list(a + b)
	c.sort()
	x = [c[0]]
	n = [1]
	p = 0
	for i in range(1, 4):
		if c[i] == x[-1]:
			n[-1] += 1
		else:
			x.append(c[i])
			n.append(1)
	if len(x) == 4:
		print(3)
	elif len(x) == 3:
		print(2)
	elif len(x) == 2:
		print(1)
	else:
		print(0)


for i in range(int(input())):
	s = input()
	ss = input()
	l = []
	for j in range(0, len(s)):
		l.append(s[j])
	for j in range(0, len(ss)):
		l.append(ss[j])
	n = set(l)
	print(len(n) - 1)


t = int(input())
otv = []
for i in range(t):
	s1 = input()
	s2 = input()
	cv = []
	for j in range(2):
		cv.append(s1[j])
		cv.append(s2[j])
	num = len(set(cv))
	if num == 4:
		otv.append(3)
	elif num == 3:
		otv.append(2)
	elif num == 2:
		otv.append(1)
	else:
		otv.append(0)
for i in otv:
	print(i)


t = int(input())
while t > 0:
	t = t - 1
	s = input()
	a = s[0]
	b = s[1]
	s = input()
	c = s[0]
	d = s[1]
	if a == b == c == d:
		print(0)
	elif a == b == c or b == c == d or a == c == d or (a == b == d):
		print(1)
	elif a == b and c == d or (a == c and b == d) or (a == d and b == c):
		print(1)
	elif a == b or c == d or b == d or (b == c) or (a == c) or (a == d):
		print(2)
	else:
		print(3)


n = int(input())
ls = []
colors = []
paracount = 0
for i in range(n):
	for j in range(2):
		str = list(input())
		ls.append(str)
	for i in range(len(ls)):
		for j in range(2):
			if ls[i][j] not in colors:
				colors.append(ls[i][j])
			else:
				paracount += 1
	print(4 - paracount - 1)
	colors = []
	paracount = 0
	ls = []


t = int(input())
for i in range(t):
	L = []
	s = input().split()
	a = input().split()
	b = a[0] + s[0]
	for j in b:
		if j not in L:
			L.append(j)
	if len(L) == 4:
		print(3)
	elif len(L) == 3:
		print(2)
	elif len(L) == 2:
		print(1)
	elif len(L) == 1:
		print(0)


from collections import defaultdict
for _ in range(int(input())):
	s1 = input()
	s2 = input()
	d = defaultdict(int)
	for i in range(2):
		d[s1[i]] += 1
		d[s2[i]] += 1
	count = 0
	present = 0
	maxx = 0
	for x in d.values():
		count += 1
		if x >= 2:
			present += 1
			maxx = max(maxx, x)
	if present == 2:
		print(1)
	elif present == 1:
		if maxx == 3:
			print(1)
		elif count == 1:
			print(0)
		else:
			print(2)
	elif count == 4:
		print(3)


t = int(input())
for testcase in range(t):
	img_set = set(input() + input())
	print(len(img_set) - 1)


t = int(input())
for _ in range(t):
	a = input()
	b = input()
	c = set(a + b)
	count = 0
	print(len(c) - 1)