n,m = map(int, input().split())
ch = str(input())
res = [ch[k] for k in range(n)]
X = ["" for _ in range(m)]
Y = ["" for _ in range(m)]
for k in range(m):
    s = str(input())
    X[k] = s[0]
    Y[k] = s[2]

al = "abcdefghijklmnopqrstuvwxyz"
A = [al[k] for k in range(26)]
B = A[:]
for k in range(m):
    a = A.index(X[k])
    b = A.index(Y[k])
    c = A[a]
    A[a] = A[b]
    A[b] = c
for j in range(n):
    a = B.index(res[j])
    res[j] = A[a]

ch = ""
for k in range(n):
    ch  = ch + res[k]
print(ch)


n,m = map(int, input().split())
ch = str(input())
X = ["" for _ in range(m)]
Y = ["" for _ in range(m)]
for k in range(m):
    s = str(input())
    X[k] = s[0]
    Y[k] = s[2]
for j in range(n):
    for k in range(m):
        if ch[j] == X[k]:
            ch = ch[:j]+Y[k]+ch[j+1:]
        elif ch[j] == Y[k]:
            ch = ch[:j]+X[k]+ch[j+1:]
print(ch)


n,m = map(int, input().split())
ch = str(input())
res = [ch[k] for k in range(n)]
X = ["" for _ in range(m)]
Y = ["" for _ in range(m)]
for k in range(m):
    s = str(input())
    X[k] = s[0]
    Y[k] = s[2]

al = "abcdefghijklmnopqrstuvwxyz"
A = [al[k] for k in range(26)]
B = A[:]
for k in range(m):
    a = B.index(X[k])
    b = B.index(Y[k])
    c = A[a]
    A[a] = A[b]
    A[b] = c
for j in range(n):
    a = B.index(res[j])
    res[j] = A[a]

ch = ""
for k in range(n):
    ch  = ch + res[k]
print(ch)


n,m = map(int, input().split())
ch = str(input())
res = [ch[k] for k in range(n)]
X = ["" for _ in range(m)]
Y = ["" for _ in range(m)]
for k in range(m):
    s = str(input())
    X[k] = s[0]
    Y[k] = s[2]
for j in range(n):
    s = res[j]
    for k in range(m):
        if s == X[k]:
            s = Y[k]
        elif s == Y[k]:
            s = X[k]
    res[j] = s
ch = ""
for k in range(n):
    ch  = ch + res[k]
print(ch)


n,m = map(int, input().split())
ch = str(input())
res = [ch[k] for k in range(n)]
X = ["" for _ in range(m)]
Y = ["" for _ in range(m)]
for k in range(m):
    s = str(input())
    X[k] = s[0]
    Y[k] = s[2]

al = "abcdefghijklmnopqrstuvwxyz"
A = [al[k] for k in range(26)]
B = A[:]
for k in range(m):
    for j in range(26):
        if A[j] == X[k]:
            A[j] = Y[k]
        elif A[j] == Y[k]:
            A[j] = X[k]

for j in range(n):
    a = B.index(res[j])
    res[j] = A[a]

ch = ""
for k in range(n):
    ch  = ch + res[k]
print(ch)


n,m = map(int, input().split())
ch = str(input())
X = ["" for _ in range(m)]
Y = ["" for _ in range(m)]
C = [0 for _ in range(n)]
for k in range(m):
    s = str(input())
    X[k] = s[0]
    Y[k] = s[2]
for k in range(m):
    C = [0 for _ in range(n)]
    for j in range(n):
        if ch[j] == X[k] and C[j]==0:
            ch = ch[:j]+Y[k]+ch[j+1:]
            C[j] = 1
        if ch[j] == Y[k] and C[j]==0:
            ch = ch[:j]+X[k]+ch[j+1:]
            C[j] = 1
print(ch)


_, m = map(int, input().split())
s = input()
for _ in range(m):
    x, y = input().split()
    s = s.replace(x, '_').replace(y, x).replace('_', y)
print(s)


_, m = map(int, input().split())
s = input()
replaced = {ch:ch for ch in 'abcdefghijklmnopqrstuvwxyz'}
for _ in range(m):
    x, y = input().split()
    for ch in replaced:
        if replaced[ch] == x:
            replaced[ch] = '_'
    for ch in replaced:
        if replaced[ch] == y:
            replaced[ch] = x
    for ch in replaced:
        if replaced[ch] == '_':
            replaced[ch] = y
print(''.join(replaced[ch] for ch in s))


_, m = map(int, input().split())
s = input()
old = 'abcdefghijklmnopqrstuvwxyz'
new = old
for _ in range(m):
	x, y = input().split()
	new = new.translate(''.maketrans(x+y, y+x))
print(s.translate(''.maketrans(old, new)))


n,m = map(int,input().split())
name = list(input())
for _ in range(m):
    a,b = input().split()
    if a in name or b in name:
        for i in range(n):
            if name[i] == a:
               name[i] = b
            elif name[i] == b:
                name[i] = a
print(''.join(name)) # print(*name, sep ='')

##########################################################


n,m = map(int,input().split())
name = list(input())
for _ in range(m):
    a,b = input().split()
    for i in range(n):
        if name[i] == a and name[i] != b:
            name[i] = b
        elif name[i] == b and name[i] != a:
            name[i] = a
print(''.join(name)) # print(*name, sep ='')

##########################################################


n, m = map(int, input().split())
s = input()
orig = 'abcdefghijklmnopqrstuvwxyz'
after = orig
for _ in range(m):
    xi, yi = input().split()
    after = after.translate(str.maketrans(xi + yi, yi + xi))

print(s.translate(str.maketrans(orig, after)))


n, m = map(int, input().split())
s = input()
for _ in range(m):
    x, y = input().split()
    s = s.translate(str.maketrans(x + y, y + x))

print(s)


def to_list(s):
    return list(map(lambda x: int(x), s.split(' ')))

def to_switch(s):
    return s[0]+s[-1]

def get_letter_dict(switches):
    alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l',
           'm','n','o','p','q','r','s','t','u','v','w','x','y','z']
    letter_dict = {}
    for letter in alphabet:
        curr_letter = letter
        for switch in switches:
            if curr_letter in switch:
                if switch[0] == curr_letter:
                    curr_letter = switch[1]
                else:
                    curr_letter = switch[0]
        letter_dict[letter] = curr_letter
    return letter_dict

def rebrand(s,letter_dict):
    out_s = ''
    for item in s:
        out_s += letter_dict[item]
    return out_s

n, m = to_list(input())
s = input()
switches = []
for i in range(m):
    switches.append(to_switch(input()))
letter_dict = get_letter_dict(switches)
print(rebrand(s,letter_dict))


n,m = input().split()
s=input()
n=int(n)
m=int(m)
#v=[chr(97+i) for i in range(26)]
l=[[] for i in range(26)]
for i in range(n):
    r=ord(s[i])-97
    l[r].append(i)
    #v[r]=s[i]

for i in range(m):
    k1,k2=input().split()
    r1,r2=ord(k1)-97,ord(k2)-97
    #v[r1],v[r2]=v[r2],v[r1]
    l[r1],l[r2]=l[r2],l[r1]

q=[0 for i in range(n)]
for i in range(26):
    q1=len(l[i])
    q2=chr(97+i)
    if(q1!=0):
        for j in range(q1):
            q[l[i][j]]=q2
for i in range(n):
    print(q[i],end="")


import string
def mp():
    return map(int,input().split())
def lt():
    return list(map(int,input().split()))
def pt(x):
    print(x)

n,m = mp()
s = input()
s1 = string.ascii_lowercase
for i in range(m):
    L = input().split()
    a,b = L[0],L[1]
    s1 = s1.translate(str.maketrans(a+b,b+a))
pt(s.translate(str.maketrans(string.ascii_lowercase,s1)))


def mp():
    return map(int,input().split())
def lt():
    return list(map(int,input().split()))
def pt(x):
    print(x)

n,m = mp()
s = input()
for i in range(m):
    L = input().split()
    a,b = L[0],L[1]
    s = s.translate(str.maketrans(a+b,b+a))
pt(s)


def mp():
    return map(int,input().split())
def lt():
    return list(map(int,input().split()))
def pt(x):
    print(x)

n,m = mp()
s = input()
S = [k for k in s]
Dict = []
for i in range(m):
    L = input().split()
    a,b = L[0],L[1]
    if Dict == []:
        Dict.append(a)
        Dict.append(b)
    elif a in Dict:
        if b not in Dict:
            Dict.insert(Dict.index(a),b)
        else:
            Dict[Dict.index(a)],Dict[Dict.index(b)] = b,a
    elif b in Dict:
        Dict.insert(Dict.index(b),a)
    else:
        for i in range(len(S)):
            if S[i] == a:
                S[i] = b
            elif S[i] == b:
                S[i] = a

for i in range(len(S)):
    if S[i] in Dict:
        r = Dict.index(S[i])
        S[i] = Dict[(r+1)%len(Dict)]
print(''.join(S))


def mp():
    return map(int,input().split())
def lt():
    return list(map(int,input().split()))
def pt(x):
    print(x)

n,m = mp()
s = input()
S = [k for k in s]
for i in range(m):
    L = input().split()
    a,b = L[0],L[1]
    for i in range(len(S)):
        if S[i] == a:
            S[i] = b
        elif S[i] == b:
            S[i] = a
print(''.join(S))


from sys import stdin
from sys import exit

live = True
if not live: stdin = open('data.in', 'r')

n, m = list(map(int, stdin.readline().strip().split()))
name = stdin.readline().strip()
switch = list("abcdefghijklmnopqrstuvwxyz")

for it in range(m):
	x, y = list(map(str, stdin.readline().strip().split()))
	for jt in range(26):
		if switch[jt] == x:
			switch[jt] = y
		else:
			if switch[jt] == y:
				switch[jt] = x
for it in name:
	print(switch[ord(it) - 97], end = "")

if not live: stdin.close()


from sys import stdin
from sys import exit

live = True
if not live: stdin = open('data.in', 'r')

n, m = list(map(int, stdin.readline().strip().split()))
name = stdin.readline().strip()
switch = list("abcdefghijklmnopqrstuvwxyz")
pos = list(range(26))

for it in range(m):
	x, y = list(map(str, stdin.readline().strip().split()))
	posX = ord(x) - 97
	posY = ord(y) - 97
	switch[pos[posX]] = y
	switch[pos[posY]] = x
	temp = pos[posX]
	pos[posX] = pos[posY]
	pos[posY] = temp

for it in name:
	print(switch[ord(it) - 97], end = "")

if not live: stdin.close()


from string import ascii_lowercase as ascii
n, m = (int(x) for x in input().split())
s = input()
f = dict(zip(ascii, ascii))
t = dict(zip(ascii, ascii))
for i in range(m):
	a, b = input().split()
	A = t[a]
	B = t[b]
	f[A] = b
	f[B] = a
	t[a] = B
	t[b] = A
for c in s:
	print(f[c], end='')
print()


n,m = map(int,input().split())
s = input()
dic = {}
for i in s:
    dic[i] = i
for i in range(m):
    x,y = map(str,input().split())
    for j in dic:
        if dic[j] == x:
            dic[j] = y
        elif dic[j] == y:
            dic[j] = x
s = list(s)
print(''.join(map(lambda x:dic[x],s)))


n,m = map(int,input().split())
s = input()
l = list(s)
for i in range(m):
    x,y = map(str,input().split())
    for i in range(len(l)):
        if l[i] == x:
            l[i] = y
        elif l[i] == y:
            l[i] = x
print(''.join(l))


import string

n, m = map(int, input().split())

s = input()

s1 = string.ascii_lowercase

for i in range(m):

	x, y = input().split()

	s1 = s1.translate(str.maketrans(x+y, y+x))

print(s.translate(str.maketrans(string.ascii_lowercase, s1)))

# Made By Mostafa_Khaled


# n = int(input())
# a = [int(i) for i in input().split()]
# s = input()
n, m = [int(i) for i in input().split()]
s = input()
x = [''] * m
y = [''] * m
for i in range(m):
    x[i], y[i] = [i for i in input().split()]
letter = [[] for i in range(26)]
for i in range(n):
    letter[ord(s[i]) - ord('a')].append(i)
for i in range(m):
    letter[ord(x[i]) - ord('a')], letter[ord(y[i]) - ord('a')] = letter[ord(y[i]) - ord('a')], letter[ord(x[i]) - ord('a')]
s_ans = [''] * n
for i in range(26):
    for j in range(len(letter[i])):
        s_ans[letter[i][j]] = chr(i + ord('a'))
print(''.join(s_ans))


n,m = [int(x) for x in input().split()]
name = input()
for i in range(m):
    newName = ""
    x,y = input().split()
    for character in name:
        if character == x:
            newName+=y
        elif character == y:
            newName += x
        else:
            newName += character
    name = newName

print(name)


n,m = [int(x) for x in input().split()]
name = input()

for i in range(m):
    x,y = input().split()
    name = name.replace(x,'.').replace(y,x).replace('.',y)

#for i in range(m):
#    newName = ""
#    x,y = input().split()
#    for character in name:
#        if character == x:
#            newName+=y
#        elif character == y:
#            newName += x
#        else:
#            newName += character
#    name = newName

print(name)


n,m = [int(x) for x in input().split()]
name = input()

for i in range(m):
    x,y = input().split()
    name = name.replace(x,'.')
    name = name.replace(y,x)
    name = name.replace('.',y)

#for i in range(m):
#    newName = ""
#    x,y = input().split()
#    for character in name:
#        if character == x:
#            newName+=y
#        elif character == y:
#            newName += x
#        else:
#            newName += character
#    name = newName

print(name)


file_object = open('TextFile1.txt','r')
n,m = [int(x) for x in file_object.readline().split()]
name = file_object.readline()

for line in file_object:
    newName = ""
    x,y = line.rstrip('\n').split()
    for character in name:
        if character == x:
            newName+=y
        elif character == y:
            newName += x
        else:
            newName += character
    name = newName

print(name)


n,m = [int(x) for x in input().split()]
name = input()

alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in range(m):
    x,y = input().split()
    indexX = alphabet.index(x)
    indexY = alphabet.index(y)
    alphabet[indexX],alphabet[indexY] = alphabet[indexY],alphabet[indexX]

newName = ''

for character in name:
    newName += alphabet[ord(character)-97]

print(newName)

#for i in range(m):
#    x,y = input().split()
#    name = name.replace(x,'.').replace(y,x).replace('.',y)

#for i in range(m):
#    newName = ""
#    x,y = input().split()
#    for character in name:
#        if character == x:
#            newName+=y
#        elif character == y:
#            newName += x
#        else:
#            newName += character
#    name = newName


n, m = input().split()
n, m = [int(n), int(m)]
name = input()
name = list(name)
for j in range(m):
  xi, yi = input().split()
  if xi == yi:
    continue
  for i in range(n):
    if name[i] == xi:
      name[i] = yi
    elif name[i] == yi:
      name[i] = xi
name = "".join(name)
print(name)


import string
n, m = input().split()
n, m = [int(n), int(m)]
name = input()
name = list(name)
buffer = {}
for ch in list(string.ascii_lowercase):
  buffer[ch] = []
for i in range(n):
  buffer[name[i]].append(i)
for j in range(m):
  xi, yi = input().split()
  temp = buffer[xi]
  buffer[xi] = buffer[yi]
  buffer[yi] = temp
for key, value in buffer.items():
  for i in value:
    name[i] = key
name = "".join(name)
print(name)


n, m = input().split()
n, m = [int(n), int(m)]
name = input()
for j in range(m):
  xi, yi = input().split()
  for i in range(n):
    if name[i] == xi:
      new_name = list(name)
      new_name[i] = yi
      name = "".join(new_name)
    elif name[i] == yi:
      new_name = list(name)
      new_name[i] = xi
      name = "".join(new_name)
print(name)


n, m = input().split()
n, m = [int(n), int(m)]
name = input()
for j in range(m):
  xi, yi = input().split()
  if xi == yi:
    continue
  for i in range(n):
    if name[i] == xi:
      new_name = list(name)
      new_name[i] = yi
      name = "".join(new_name)
    elif name[i] == yi:
      new_name = list(name)
      new_name[i] = xi
      name = "".join(new_name)
print(name)


from math import sqrt, pow, log, log2, log10, exp
from copy import deepcopy
from fractions import gcd

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

def read_int():
    return read_ints()[0]

def read_floats():
    return list(map(float, input().split()))

def read_float():
    return read_floats()[0]

def format_list(l):
    return ' '.join(list(map(str, l)))

def one_dim_array(n, value=0):
    return [deepcopy(value) for x in range(n)]

def two_dim_array(n, m, value=0):
    return [[deepcopy(value) for x in range(m)] for x in range(n)]

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, sqrt(n) + 1):
        if n % i == 0:
            return False
    return True

def max_len_sublist(l, f):
    start, max_length, length = 0, 0, 0
    for i in range(1, len(l)):
        if f(l[i], l[i - 1]):
            length += 1
        else:
            if max_length < length:
                start = i - length
                max_length = length
            length = 0
    return start, max_length

def tf_to_yn(b):
    return 'YES' if b else 'NO'

def longest_non_descent_subsequence(s, restore_sequence=False):
    d = one_dim_array(len(s), 0)
    for i in range(len(s)):
        possible = [d[j] + 1 if s[j] <= s[i] else 1 for j in range(i)]
        d[i] = 1 if len(possible) == 0 else max(possible)

    if not restore_sequence:
        return d[-1] if len(d) != 0 else 0

def update_ch(ch, f, t):
    addedf = False
    addedt = False
    for key in ch.keys():
        value = ch[key]
        if value == f:
            ch[key] = t
            addedf = True
        if value == t:
            ch[key] = f
            addedt = True
    if not addedf:
        ch[f] = t
    if not addedt:
        ch[t] = f

    return ch

n, m = read_ints()
s = list(input())
ch = {}

for i in range(1, m + 1):
    f, t = input().split()
    if f != t:
        update_ch(ch, f, t)

def map_with_ch(ch, x):
    if x in ch:
        return ch[x]
    else:
        return x

print(''.join(list(map(lambda x: map_with_ch(ch, x), s))))


from math import sqrt, pow, log, log2, log10, exp
from copy import deepcopy
from fractions import gcd

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

def read_int():
    return read_ints()[0]

def read_floats():
    return list(map(float, input().split()))

def read_float():
    return read_floats()[0]

def format_list(l):
    return ' '.join(list(map(str, l)))

def one_dim_array(n, value=0):
    return [deepcopy(value) for x in range(n)]

def two_dim_array(n, m, value=0):
    return [[deepcopy(value) for x in range(m)] for x in range(n)]

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, sqrt(n) + 1):
        if n % i == 0:
            return False
    return True

def max_len_sublist(l, f):
    start, max_length, length = 0, 0, 0
    for i in range(1, len(l)):
        if f(l[i], l[i - 1]):
            length += 1
        else:
            if max_length < length:
                start = i - length
                max_length = length
            length = 0
    return start, max_length

def tf_to_yn(b):
    return 'YES' if b else 'NO'

def longest_non_descent_subsequence(s, restore_sequence=False):
    d = one_dim_array(len(s), 0)
    for i in range(len(s)):
        possible = [d[j] + 1 if s[j] <= s[i] else 1 for j in range(i)]
        d[i] = 1 if len(possible) == 0 else max(possible)

    if not restore_sequence:
        return d[-1] if len(d) != 0 else 0

def map_character(ch, f, t):
    if ch == f:
        return t
    elif ch == t:
        return f
    else:
        return ch

n, m = read_ints()
s = list(input())

for i in range(1, m + 1):
    f, t = input().split()
    s = list(map(lambda ch: map_character(ch, f, t), s))
print(''.join(s))


fixed = 'abcdefghijklmnopqrstuvwxyz'
new = fixed
_, m = map (int, input().split())
str = input()
for _ in range (m) :
    x, y = input().split()
    new = new.translate (''.maketrans (x + y, y + x))
print (str.translate (''.maketrans (fixed, new)))


n, m = map(int, input().split())
s = input()
d = {}
for i in range(m):
    a, b = input().split()
    for k in d:
        if d[k] == a:
            d[k] = b
        elif d[k] == b:
            d[k] = a
    if a not in d:
        d[a] = b
    if b not in d:
        d[b] = a
r = ''
for c in s:
    if c in d:
        r+=d[c]
    else:
        r+=c

print(r)


n, m = map(int, input().split())
s = input()
for i in range(m):
    a,b = input().split()
    ns = ''
    for c in s:
        if c == a:
            ns+=b
        elif c == b:
            ns+=a
        else:
            ns+=c
    s = ns
print(s)


IL = lambda: list(map(int, input().split()))
IS = lambda: input().split()
I = lambda: int(input())
S = lambda: input()

n, m = IL()
name = S()
letters = dict([[chr(i), chr(i)] for i in range(97, 123)])

for i in range(m):
    l1, l2 = IS()
    letters[l1], letters[l2] = letters[l2], letters[l1]

rletters = {v: k for k, v in letters.items()}
print("".join([rletters[l] for l in name]))


from sys import stdin,stdout
d={}
a,b=map(int,stdin.readline().split())
z=['0']*(a+1)
for i in range(26):
    d[chr(97+i)]=()
d['\n']=()
for i,j in enumerate(stdin.readline()):
    d[j]+=(i,)
for _ in " "*b:
    c,c1=map(str,input().split())
    d[c1],d[c]=d[c],d[c1]
for i in d:
    for j in d[i]:
            z[j] = i
stdout.write("".join(z))


from sys import stdin,stdout
d={}
for i in range(26):
    d[chr(97+i)]=()
d['\n']=()
a,b=map(int,stdin.readline().split())
z=stdin.readline().replace('',' ').split()
for i,j in enumerate(z):
    d[j]+=(i,)
for _ in " "*b:
    c,c1=stdin.readline().split()
    d[c1],d[c]=d[c],d[c1]
for i in d:
    for j in d[i]:
            z[j] = i
stdout.write("".join(z))


d={}
a,b=map(int,input().split())
z=['0']*a
for i in range(26):
    d[chr(97+i)]=()
for i,j in enumerate(input()):
    d[j]+=(i,)
for _ in " "*b:
    c,c1=map(str,input().split())
    d[c1],d[c]=d[c],d[c1]
for i in d:
    for j in d[i]:
            z[j] = i
print("".join(z))


from sys import stdin,stdout
a,b=map(int,stdin.readline().split())
z=stdin.readline().replace('',' ').split()
ans_digit=[*range(27)]
for _ in " "*b:
    c,d=map(str,stdin.readline().split())
    ans_digit[ord(c)-97],ans_digit[ord(d)-97]=ans_digit[ord(d)-97],ans_digit[ord(c)-97]
ans_char=[]
for i in range(27):
    w=ans_digit[i];p=i
    while w!=i:p=w;w=ans_digit[w]
    ans_char+=[p]
for i in range(a):
    z[i]=chr(97+ans_char[ord(z[i])-97])
stdout.write("".join(z))


m = int(input().split()[1])
name = input()
for i in range(m):
    a,b = input().split()
    if (a != b):
        name = name.translate(str.maketrans(a+b, b+a))
print(name)


def tr(d,a,b):
    for i, j in d.items():
        if j == a:
            d[i] = b
        elif j == b:
            d[i] = a
    if not (a in d.keys()):
        d.update({a:b})
    if not (b in d.keys()):
        d.update({b:a})

m = int(input().split()[1])
name = input()
s = set(name)
d = dict()
for i in range(m):
    a,b = input().split()
    if a != b:
        tr(d,a,b)
name = name.translate(str.maketrans(''.join(d.keys()),''.join(d.values())))
print(name)


def ch(s,a,b):
    if s == a:
        s = b
    elif s == b:
        s = a
    return s

m = int(input().split()[1])
name = input()
for i in range(m):
    a,b = input().split()
    name = ''.join(ch(c,a,b) for c in name)
print(name)


m = int(input().split()[1])
name = input()
for i in range(m):
    a,b = input().split()
    name = name.replace(a,'0').replace(b,a).replace('0',b)
print(name)


n, m = map(int, input().split())
original_name = input()
changes = [input().split() for _ in range(m)]

original_char_dict_list = sorted(list(set(original_name)))
modified_char_dict_list = sorted(list(set(original_name)))

for pair in changes:
    for i, c in enumerate(modified_char_dict_list):
        if c == pair[0]:
            modified_char_dict_list[i] = pair[1]
        elif c == pair[1]:
            modified_char_dict_list[i] = pair[0]

dictionary = {c: modified_char_dict_list[i] for i, c in enumerate(original_char_dict_list)}
name_list = list(original_name)

for i, c in enumerate(name_list):
    name_list[i] = dictionary[c]

print(''.join(name_list))


n,m=map(int,input().split())
S=input()
for i in range(m) :
    a,b=map(str,input().split())

    for i in range(n) :
        if S[i]==a :
            S=S[:i]+b+S[i+1:]
        else :
             if S[i]==b :
                 S=S[:i]+a+S[i+1:]
print(S)


n, m = map(lambda x: int(x), input().split())
name = input()

for i in range(m):
    x, y = input().split()
    name = list(map(lambda c: y if c == x else x if c == y else c, name))

name = ''.join(name)
print(name)


n, m = map(int, input().split())
name = input()
changes = [input().split() for i in range(m)]

changes_table = sorted(list(set(name)))

for x, y in changes:
    for i, c in enumerate(changes_table):
        if c == x:
            changes_table[i] = y
        elif c == y:
            changes_table[i] = x

lookup_table = { c: changes_table[i] for i, c in enumerate(sorted(list(set(name)))) }

final_name = ''.join(map(lambda c: lookup_table[c], name))
print(final_name)


import sys
import string
read = lambda: list(map(int, sys.stdin.readline().split()))

n, m = read()
s = sys.stdin.readline().strip()
design = {c:c for c in string.ascii_lowercase}
for i in range(m):
   a, b = sys.stdin.readline().split()
   design[a], design[b] = design[b], design[a]
design2 = {b:a for a,b in design.items()}
print(''.join(design2[c] for c in s))


"""
Codeforces Round #327 (Div. 2)

Problem 591 B. Rebranding

@author yamaton
@date 2015-11-06
"""

import string
import sys

def solve(s, pairs):
    """
    O(Σ + N + M)
    :param s:
    :param pairs:
    :return:
    """
    origin_of = {c: c for c in string.ascii_lowercase}
    for (c1, c2) in pairs:
        origin_of[c1], origin_of[c2] = origin_of[c2], origin_of[c1]

    d = {v: k for k, v in origin_of.items()}
    return ''.join(d[c] for c in s)

def solve0(s, pairs):
    """
    O(Σ M + N)
    :param s:
    :param pairs:
    :return:
    """
    d = {c: c for c in string.ascii_lowercase}
    for (c1, c2) in pairs:
        for c in string.ascii_lowercase:
            if d[c] == c1:
                d[c] = c2
            elif d[c] == c2:
                d[c] = c1
    return ''.join(d[c] for c in s)

def main():
    [n, m] = [int(i) for i in input().strip().split()]
    s = input().strip()
    assert len(s) == n
    pairs = [tuple(input().strip().split()) for _ in range(m)]
    result = solve(s, pairs)
    print(result)

if __name__ == '__main__':
    main()


"""
Codeforces Round #327 (Div. 2)

Problem 591 B. Rebranding

@author yamaton
@date 2015-11-06
"""

import itertools as it
import functools
import operator
import collections
import math
import sys

import string

def solve(s, pairs, n, m):
    d = {c: c for c in string.ascii_lowercase}
    for (c1, c2) in pairs:
        for c in string.ascii_lowercase:
            if d[c] == c1:
                d[c] = c2
            elif d[c] == c2:
                d[c] = c1
    return ''.join(d[c] for c in s)

def print_stderr(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

def main():
    [n, m] = [int(i) for i in input().strip().split()]
    s = input().strip()
    assert len(s) == n
    pairs = [tuple(input().strip().split()) for _ in range(m)]
    result = solve(s, pairs, n, m)
    print(result)

if __name__ == '__main__':
    main()


import math
from decimal import Decimal
def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return n,b

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return n,b,c

def dv():
	n, m = map(int, input().split())
	return n,m

def dva():
	n, m = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return n,m,b

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return n,b,m,c

def dvs():
	n = int(input())
	m = int(input())
	return n, m

n, m = map(int, input().split())
s = input()
d = {}
for i in range(97, 123):
	d[chr(i)] = chr(i)
for i in range(m):
	x, y = input().split()
	d[x], d[y] = d[y], d[x]
new = ''
t = {}
for i in d:
	t[d[i]] = i
for i in s:
	new += t[i]
print(new)


#!/usr/bin/env python3

from sys import stdin

inp = stdin.readline().split()

m = int(inp[1])

word = stdin.readline().strip()

for i in range(0, m):
    replacement = stdin.readline().split()
    fr = replacement[0]
    to = replacement[1]

    new_word = ''

    for l in word:
        if l == fr:
            new_word += to
        elif l == to:
            new_word += fr
        else:
            new_word += l

    word = new_word

print(word)


#!/usr/bin/env python3

from sys import stdin

inp = stdin.readline().split()

m = int(inp[1])

word = stdin.readline().strip()

replaces = {}

for i in range(0, m):
    replacement = stdin.readline().split()
    fr = replacement[0]
    to = replacement[1]

    for key, value in replaces.items():
        if value == fr:
            replaces[key] = to
        if value == to:
            replaces[key] = fr

    if fr not in replaces:
        replaces[fr] = to

    if to not in replaces:
        replaces[to] = fr

table = str.maketrans(*["".join(x) for x in zip(*replaces.items())])
word = word.translate(table)

print(word)


#!/usr/bin/env python3

from sys import stdin
import re

inp = stdin.readline().split()

m = int(inp[1])

word = stdin.readline().strip()

for i in range(0, m):
    replacement = stdin.readline().split()
    fr = replacement[0]
    to = replacement[1]

    rule = {fr: to, to: fr}
    regexp = '|'.join(rule)
    word = re.sub(regexp, lambda p: rule[p.group()], word)

print(word)


#!/usr/bin/env python3

from sys import stdin

inp = stdin.readline().split()

m = int(inp[1])

word = stdin.readline().strip()

for i in range(0, m):
    replacement = stdin.readline().split()
    fr = replacement[0] + replacement[1]
    to = replacement[1] + replacement[0]

    table = str.maketrans(fr, to)
    word = word.translate(table)

print(word)


import string
n, m = map(int, input().split())
s = input()
s1 = string.ascii_lowercase
for i in range(m):
	x, y = input().split()
	s1 = s1.translate(str.maketrans(x+y, y+x))
print(s.translate(str.maketrans(string.ascii_lowercase, s1)))


#include <stdio.h>
int main()
{
    int i, j, n, one = 0, two = 0, three = 0, a;
    scanf("%d", &n);
    for(i = 0; i <n; i++){
        scanf("%d", &a);
        if(a==1){
            one++;
        }
        else if(a==2){
            two++;
        }
        else{
            three++;
        }
    }
    if(three>= two && three >= one){
        printf("%d", n-three);
    }
    else if( two>= three && two >= one){
        printf("%d", n-two);
    }
    else{
        printf("%d", n-one);
    }
    return 0;

}


#include <stdio.h>

int max(int a, int b, int c)
{
     int m = a;

     if (b > m) m = b;
     if (c > m) m = c;

     return m;
}

int main()
{
     int n, x, i;
     int a[3] = {0};

     scanf("%d", &n);

     for (i = 0; i < n; i++) {
	  scanf("%d", &x);

	  a[x - 1]++;
     }

     printf("%d\n", a[0] + a[1] + a[2] - max(a[0], a[1], a[2]));

     return 0;
}


#include <stdio.h>

int main(void) {
	// your code goes here
	int n,a;
	scanf("%d",&n);
	int i,j=0,k=0,l=0;
	for(i=0;i<n;i++)
	{
	    scanf("%d",&a);
	    if(a==1)j++;
	    if(a==2)k++;
	    if(a==3)l++;

	}
	int max=j;
	if(j>k){ if(j>l)max=j; else max=k;       }
	else {

	    if(k>l)max=k; else max=l;
	}

	printf("\n%d",n-max);
	return 0;
}


#include <stdio.h>

int main(void) {
	// your code goes here
	int n,j;
	scanf("%d",&n);
	int i,a=0,b=0,c=0;
	for(i=0;i<n;i++)
	{
	    scanf("%d",&j);
	    if(j==1)a++;
	    if(j==2)b++;
	    if(j==3)c++;

	}
	int max=0;
	if(a>=b && a>=c)
	max=a;

	if(b>=a && b>=c)
	max=b;
	 if(c>=a && c>=b) max=c;

	printf("\n%d",n-max);
	return 0;
}


#include<stdio.h>
int main()
{
    long long int n,a,i,p=0,q=0,r=0;
    scanf("%I64d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&a);
        if(a==1) p++;
        else if(a==2) q++;
        else if(a==3) r++;
    }
    if(p>=q&&p>=r) printf("%I64d ",q+r);
    else if(q>=p&&q>=r) printf("%I64d ",p+r);
    else if(r>=p&&r>=q) printf("%I64d ",p+q);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,on=0,tw=0,th=0,a;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a==1)
        on++;
        else if(a==2)
        tw++;
        else
        th++;
    }
    if(on>tw && on>th)
    printf("%d",n-on);
    else if(tw>on && tw>th)
    printf("%d",n-tw);
    else if(th>tw && th>on)
    printf("%d",n-th);
return 0;
}


#include<stdio.h>
int main()
{
    int n,i,on=0,tw=0,th=0,a;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a==1)
        on++;
        else if(a==2)
        tw++;
        else
        th++;
    }
    if(on>=tw && on>=th)
    printf("%d",n-on);
    else if(tw>=on && tw>=th)
    printf("%d",n-tw);
    else if(th>=tw && th>=on)
    printf("%d",n-th);
return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(){

    int n, x, ans;
    int ct[4];
    ct[1] = ct[2] = ct[3] = 0;

    scanf("%d", &n );
    while( n-- ){
           scanf("%d", &x );
           ct[x]++;
    }

    ans = ct[1] + ct[2];
    if( ct[1]+ct[3] < ans ) ans = ct[1] + ct[3];
    if( ct[2]+ct[3] < ans ) ans = ct[2] + ct[3];
    printf("%d\n", ans );

    return 0;
}


/*
                                Badhan Sen
                            Student of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybd9@gmail.com

*/
#include <stdio.h>

int main ()
{
    int n, i, array[100000], a=0, b=0, c=0;
    scanf ("%d", &n);

    for (i=0; i<n; i++){
        scanf ("%d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if (a>b && a>c)
        printf ("%d", b+c);

    else if (b>a && b>c)
        printf ("%d", a+c);

    else if (c>a && c>b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    return 0;
}


/*
                                BaI64dhan Sen
                            StuI64dent of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybI64d9@gmail.com

*/
#include <stdio.h>

void main ()
{
    long long int n, i, array[100000], a=0, b=0, c=0;
    scanf ("%I64d", &n);

    for (i=0; i<n; i++){
        scanf ("%I64d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if (a>b && a>c)
        printf ("%I64d", b+c);

    else if (b>a && b>c)
        printf ("%I64d", a+c);

    else if (c>a && c>b)
        printf ("%I64d", a+b);

    else if (a==b && b==c)
        printf ("%I64d", a+c);

    else if ((a>b && a>c) && b==c)
        printf ("%I64d", b+c);

    else if ((b>a && b>c) && a==c)
        printf ("%I64d", a+c);

    else if ((c>a && c>b) && a==b)
        printf ("%I64d", a+b);

    else if (a==b && b==c)
        printf ("%I64d", a+c);

    else if (n==2)
        printf ("1");

    return 0;
}


/*
                                Badhan Sen
                            Student of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybd9@gmail.com

*/
#include <stdio.h>

int main ()
{
    int n, i, array[100000], a=0, b=0, c=0;
    scanf ("%d", &n);

    for (i=0; i<n; i++){
        scanf ("%d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if ((a>b && a>c) || b==c)
        printf ("%d", b+c);

    else if ((b>a && b>c) || a==c)
        printf ("%d", a+c);

    else if ((c>a && c>b) || a==b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    else if (a==b)
        printf ("1");

    else if (a==c)
        printf ("1");

    else if (b==c)
        printf ("1");

    return 0;
}


/*
                                Badhan Sen
                            Student of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybd9@gmail.com

*/
#include <stdio.h>

int main ()
{
    int n, i, array[100000], a=0, b=0, c=0;
    scanf ("%d", &n);

    for (i=0; i<n; i++){
        scanf ("%d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if (a>b && a>c)
        printf ("%d", b+c);

    else if (b>a && b>c)
        printf ("%d", a+c);

    else if (c>a && c>b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    else if (a==b)
        printf ("1");

    else if (a==c)
        printf ("1");

    else if (b==c)
        printf ("1");

    return 0;
}


/*
                                Badhan Sen
                            Student of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybd9@gmail.com

*/
#include <stdio.h>

int main ()
{
    int n, i, array[100000], a=0, b=0, c=0;
    scanf ("%d", &n);

    for (i=0; i<n; i++){
        scanf ("%d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if (a>b && a>c)
        printf ("%d", b+c);

    else if (b>a && b>c)
        printf ("%d", a+c);

    else if (c>a && c>b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    else if ((a>b && a>c) && b==c)
        printf ("%d", b+c);

    else if ((b>a && b>c) && a==c)
        printf ("%d", a+c);

    else if ((c>a && c>b) && a==b)
        printf ("%d", a+b);

    else if (b==c && a<b)
        printf ("%d", a+b);

    else if (a==c && b<c)
        printf ("%d", b+a);

    else if (a==b && c<a)
        printf ("%d", c+a);

    else if (n==2)
        printf ("1");

    return 0;
}


/*
                                Badhan Sen
                            Student of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybd9@gmail.com

*/
#include <stdio.h>

int main ()
{
    int n, i, array[100000], a=0, b=0, c=0;
    scanf ("%d", &n);

    for (i=0; i<n; i++){
        scanf ("%d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if (a>b && a>c)
        printf ("%d", b+c);

    else if (b>a && b>c)
        printf ("%d", a+c);

    else if (c>a && c>b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    else if ((a>b && a>c) && b==c)
        printf ("%d", b+c);

    else if ((b>a && b>c) && a==c)
        printf ("%d", a+c);

    else if ((c>a && c>b) && a==b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    else if (n==2)
        printf ("1");

    return 0;
}


/*
                                Badhan Sen
                            Student of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybd9@gmail.com

*/
#include <stdio.h>

int array[10000000];

int main ()
{
    int n, i, a=0, b=0, c=0;

    scanf ("%d", &n);

    for (i=0; i<n; i++){
        scanf ("%d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if (a>b && a>c)
        printf ("%d", b+c);

    else if (b>a && b>c)
        printf ("%d", a+c);

    else if (c>a && c>b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    else if ((a>b && a>c) && b==c)
        printf ("%d", b+c);

    else if ((b>a && b>c) && a==c)
        printf ("%d", a+c);

    else if ((c>a && c>b) && a==b)
        printf ("%d", a+b);

    else if (b==c && a<b)
        printf ("%d", a+b);

    else if (a==c && b<c)
        printf ("%d", b+a);

    else if (a==b && c<a)
        printf ("%d", c+a);

    else if (n==2)
        printf ("1");

    return 0;
}


/*
                                Badhan Sen
                            Student of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybd9@gmail.com

*/
#include <stdio.h>

int main ()
{
    int n, i, array[100000], a=0, b=0, c=0;
    scanf ("%d", &n);

    for (i=0; i<n; i++){
        scanf ("%d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if (a>b && a>c)
        printf ("%d", b+c);

    else if (b>a && b>c)
        printf ("%d", a+c);

    else if (c>a && c>b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    else if ((a>b && a>c) && b==c)
        printf ("%d", b+c);

    else if ((b>a && b>c) && a==c)
        printf ("%d", a+c);

    else if ((c>a && c>b) && a==b)
        printf ("%d", a+b);

    else if (a==b && b==c)
        printf ("%d", a+c);

    else if (a==b)
        printf ("1");

    else if (a==c)
        printf ("1");

    else if (b==c)
        printf ("1");

    return 0;
}


/*
                                Badhan Sen
                            Student of C.S.E
                jessore University of Science & Technology
                        Mail: galaxybd9@gmail.com

*/
#include <stdio.h>

int main ()
{
    int n, i, array[100000], a=0, b=0, c=0;
    scanf ("%d", &n);

    for (i=0; i<n; i++){
        scanf ("%d", &array[i]);
    }
    for (i=0; i<n; i++){
        if (array[i]==1)
            a++;
    }
    for (i=0; i<n; i++){
        if (array[i]==2)
            b++;
    }
    for (i=0; i<n; i++){
        if (array[i]==3)
            c++;
    }
    if (a>b && a>c)
        printf ("%d", b+c);

    else if (b>a && b>c)
        printf ("%d", a+c);

    else if (c>a && c>b)
        printf ("%d", a+b);

    return 0;
}


#include<stdio.h>
#include<math.h>
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
int main()
{
long long n,i,x,a[3]={0};
scanf("%lld",&n);
for(i=0;i<n;i++)
{
scanf("%lld",&x);
x--;
a[x]++;
}
printf("%d",n-(MAX(a[0],MAX(a[1],a[2]))));
return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,a[4]={0},s=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=1;i<=3;i++)
    {
        if(a[i]>s)
            s=a[i];
    }
    printf("%d",n-s);
    return 0;
}


#include<stdio.h>
#define For(X,Y,Z) for(int X=Y;X<Z;X++)
int max(int x,int y)
{
	if(x>y) return x;
	else return y;
}
int main()
{
	int a[4]={0},n,m;
	scanf("%d",&n);
	a[1]=a[2]=a[3]=0;
	For(i,0,n)
	scanf("%d",&m),a[m]++;
	n=a[1]+a[2]+a[3];
	printf("%d\n",n-max(a[1],max(a[2],a[3])));
	return 0;
}


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,a[4]={0},s=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=1;i<=3;i++)
    {
        s=max(s,a[i]);
    }
    printf("%d",n-s);
    return 0;
}


#include<stdio.h>

int main(){
  int n,c = 0;
  scanf("%d", &n);
  int i = 0,a[n],start;
  for(i = 0; i < n; i++){
    int x;
    scanf("%d",&x);
    if(!i) {
      start = x;
      continue;
    }
    start++;
    int curr = (start - 1) % 3 + 1;
    if(x != curr) c++;
    //printf("curr = %d x = %d c = %d\n", curr, x, c);
  }
  printf("%d\n", c);
  return 0;
}


#include <stdio.h>

int main()
{
    int n,a,i,ara[105],max;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
    }
    int count1=0,count2=0,count3=0;
    for(i=0;i<n;i++){
        if(ara[i]==1){
            count1++;
        }
        else if(ara[i]==2){
            count2++;
        }
        else{
            count3++;
        }
    }
    if(count1>count2){
        if(count1>count3){
            max=count1;
        }
        else{
            max=count3;
        }
    }
    else{
        if(count2>count3){
            max=count2;
        }
        else{
            max=count3;
        }
    }
    printf("%d\n",n-max);

    return 0;
}


#include <stdio.h>

int main()
{
    int n,a,i,ara[1000005],max;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
    }
    int count1=0,count2=0,count3=0;
    for(i=0;i<n;i++){
        if(ara[i]==1){
            count1++;
        }
        else if(ara[i]==2){
            count2++;
        }
        else{
            count3++;
        }
    }
    if(count1>count2){
        if(count1>count3){
            max=count1;
        }
        else{
            max=count3;
        }
    }
    else{
        if(count2>count3){
            max=count2;
        }
        else{
            max=count3;
        }
    }
    printf("%d\n",n-max);

    return 0;
}


#include <stdio.h>

int n , a , i , j , k, num[4] ;

int main()
{
    scanf("%d", &n ) ;
    while( ++i <= n )
    {
        scanf("%d", &a ) ;
        num[a]++ ;
    }
    for( i = 1 ; i < 4 ;i++) if ( k < num[i] ) k = num[i] ;

    printf("%d", n - k ) ;
 return 0 ;
 }


#include <stdio.h>
int main()
{
    int n,a=0,b=0,c=0,x,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x==1)a++;
        else if(x==2)b++;
        else  c++;
    }
    if(a>b&&a>c) printf("%d",b+c);
    else if(b>c&&b>a)printf("%d",a+c);
    else printf("%d",a+b);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,a=0,b=0,c=0,x,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x==1)a++;
        else if(x==2)b++;
        else  c++;
    }
    if(a>b&&a>c)printf("%d",b+c);
    else if(b>c&&b>a)printf("%d",a+c);
    else if(c>a&&c>b)printf("%d",a+b);
    else if(a==b&&b==c&&a==c) printf("%d",a+b);
    else if(a==b)printf("%d",c+a);
    else if(c==b)printf("%d",a+b);
    else if(a==c)printf("%d",a+b);
    else ;
    return 0;
}


#include<stdio.h>
int main()
{
long int n,i,count1=0,count2=0,count3=0;
long int max,replace;
int a;
scanf("%ld",&n);
//printf("%ld",n);
for(i=0;i<n;i++)
{
scanf("%d",&a);
if(a==1)
count1++;
else if(a==2)
count2++;
else count3++;
}
max=count1;
replace=count2+count3;
if(count2>max)
{
max=count2;
replace=count1+count3;
}
if(count3>max)
{
max=count3;
replace=count1+count2;
}
printf("%ld",replace);
return 0;
}


#include<stdio.h>
int main()
{
	int n,count1=0,count2=0,count3=0,X=0,i;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==1) count1++;
		if(a[i]==2) count2++;
		if(a[i]==3) count3++;
		X=max(count1,count2,count3);
	}
		printf("%d",n-X);
	return 0;
}

	int max(int a,int b,int c)
	{
	  int M;
	  if(a>=b && a>=c)
		  M=a;
	  else if(b>=a && b>=c)
		  M=b;
	  else if(c>=a && c>=b)
		  M=c;
	  return M;
	}


#include <stdio.h>

int main() {
	int n,a,big,i,arr[4]={0};
	scanf("%d",&n);

	for(i=1;i<=n;i++)
	{
	 scanf("%d",&a);
	 arr[a]++;
	}
	big=arr[1];
	for(i=1;i<=n;i++)
	if(big<=arr[i])
	big=arr[i];
	printf("%d",n-big);

	return 0;
}


#include <stdio.h>

int main() {
	int n,a,big,i,arr[1000001];
	scanf("%d",&n);

	for(i=1;i<=n;i++)
	{
	 scanf("%d",&a);
	 arr[a]++;
	}
	big=arr[1];
	for(i=1;i<=n;i++)
	if(big<arr[i])
	big=arr[i];
	printf("%d",n-big);

	return 0;
}


#include <stdio.h>

int main() {
	int n,a,big,i,arr[4]={0};
	scanf("%d",&n);

	for(i=1;i<=n;i++)
	{
	 scanf("%d",&a);
	 arr[a]++;
	}
	big=arr[1];
	for(i=1;i<=3;i++)
	if(big<arr[i])
	big=arr[i];
	printf("%d",n-big);

	return 0;
}


#include<stdio.h>
int main()
{
	long long int n,i,c1=0,c2=0,c3=0,s1,s2,s3,min;
	int a;
	scanf("%lld", &n);
	for (i=0;i<n;i++)
	{
		scanf("%lld", &a);
		if (a==1) c1++;
		if (a==2) c2++;
		if (a==3) c3++;
	}
	s1=c1+c2;
	s2=c2+c3;
	s3=c3+c1;
	if (s1<s2) min=s1;
	else min=s2;
	if (s3<min) min=s3;
	printf("%lld", min);
}


#include<stdio.h>
int main()
{
	long long int n,i,c1=0,c2=0,c3=0,s1,s2,s3,max;
	int a;
	scanf("%lld", &n);
	for (i=0;i<n;i++)
	{
		scanf("%lld", &a);
		if (a==1) c1++;
		if (a==2) c2++;
		if (a==3) c3++;
	}
	if (c1>c2) max=c1;
	else max=c2;
	if (c3>max) max=c3;
	if (max==c1) printf("%lld", c2+c3);
	else if (max==c2) printf("%lld", c1+c3);
	else if (max==c3) printf("%lld", c2+c1);
}


#include<stdio.h>
int main()
{
	long long int n,i,c1=0,c2=0,c3=0,s1,s2,s3,min;
	int a;
	scanf("%lld", &n);
	for (i=0;i<n;i++)
	{
		scanf("%lld", &a);
		if (a==1) c1++;
		if (a==2) c2++;
		if (a==3) c3++;
	}
	s1=c1+c2;
	s2=c2+c3;
	s3=c3+c1;
	if (s1<s2) min=s1;
	else min=s2;
	if (s3<min) min=s3;
	printf("%lld", min);
return 0;
}


#include<stdio.h>
int main()
{
	long long int n,i,c1=0,c2=0,c3=0,s1,s2,s3,min;
	int a;
	scanf("%lld", &n);
	for (i=0;i<n;i++)
	{
		scanf("%lld", &a);
		if (a==1) c1++;
		if (a==2) c2++;
		if (a==3) c3++;
	}
	s1=c1+c2;
	s2=c2+c3;
	s3=c3+c1;
//	printf("%lld %lld %lld\n",s1,s2,s3);
	if (s1<s2) min=s1;
	else min=s2;
	if (s3<min) min=s3;
	printf("%lld", min);
}


#include<stdio.h>
int main()
{
	long long int n,i,c1=0,c2=0,c3=0,s1,s2,s3,max,a;
	scanf("%lld", &n);
	for (i=0;i<n;i++)
	{
		scanf("%lld", &a);
		if (a==1) c1++;
		if (a==2) c2++;
		if (a==3) c3++;
	}
	if (c1>c2) max=c1;
	else max=c2;
	if (c3>max) max=c3;
	if (max==c1) printf("%lld", c2+c3);
	else if (max==c2) printf("%lld", c1+c3);
	else if (max==c3) printf("%lld", c2+c1);
}


#include <stdio.h>

int main (void) {

    int n, i, a=0, b=0, c=0;
    scanf("%d", &n);
    int ar[n];
    for( i=0; i<n; i++) {
        scanf("%d", &ar[i]);
        if(ar[i]==1) a++;
        if(ar[i]==2) b++;
        if(ar[i]==3) c++;
    }

    if(b>=c && b>=a) printf("%d\n", n-b);
    else if(c>=b && c>=a) printf("%d\n", n-c);
    else if(a>=c && a>=b) printf("%d\n", n-a);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int m,n,count=0,ara[1000000],i,o,j,l,cu=0,as=0;
    //int ara[1000000];
    scanf("%d",&n);
    for(i=0;i<n;i++) {
        scanf("%d",&ara[i]);
    }
    for(i=0,1<=n<=1000000;i<n;i++) {
        if(ara[i]==1) {
            count++;
        }
        else if(ara[i]==2) {
            cu++;
        }
        else if(ara[i]==3) {
            as++;
        }
    }
    if(count>=cu && count>=as) {
        printf("%d",n-count);
    }
    else if(cu>=count && cu>=as) {
        printf("%d",n-cu);
    }
    else if(as>=count && as>=cu) {
        printf("%d",n-as);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    long long int m,n,count=0,i,o,j,l,cu=0,as=0;
    long long int ara[100];
    scanf("%I64d",&n);
    for(i=0;i<n;i++) {
        scanf("%I64d",&ara[i]);
    }
    for(i=0,1<=n<=1000000;i<n;i++) {
        if(ara[i]==1) {
            count++;
        }
        else if(ara[i]==2) {
            cu++;
        }
        else if(ara[i]==3) {
            as++;
        }
    }
    if(count>=cu && count>=as) {
        printf("%I64d",n-count);
    }
    else if(cu>=count && cu>=as) {
        printf("%I64d",n-cu);
    }
    else if(as>=count && as>=cu) {
        printf("%I64d",n-as);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    long long n;
    scanf("%I64d",&n);
    int s[n];
    long a=0,b=0,c=0;
    long long i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&s[i]);
        if (s[i]!=2) b++;
        if (s[i]!=1) a++;
        if (s[i]!=3) c++;

    }
    long d=(a<b) ?(a<c) ? a : c : (b<c) ? b :c ;
    printf("%ld",d);
    return 0;
}


#include<stdio.h>
main(){
    int n,i;
    scanf("%d",&n);
    int a[n],o=0,t=0,tr=0;
    for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]==1) o++;
    if(a[i]==2) t++;
    if(a[i]==3) tr++;
    }
    int max=o;
    if(max<t) max=t;
    if(max<tr) max=tr;
    printf("%d",n-max);
    return 0;
}


#include<stdio.h>
int main()
{
    int a;
    long n,a1=0,a2=0,a3=0;
    scanf("%ld",&n);
    while(n--)
    {
        scanf("%d",&a);
        if(a==1)
            a1++;
        else if(a==2)
            a2++;
        else a3++;
    }
    if(a3>=a1&&a3>=a2)
        printf("%ld",a1+a2);
    else if(a2>=a1&&a2>=a3)
        printf("%ld",a1+a3);
    else printf("%ld",a2+a3);

    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,max,x=0,y=0,z=0;
    char a[1000000];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]==1)
        x++;
        else if(a[i]==2)
        y++;
        else
        z++;
    }
    if(x>y)
        max=x;
    else
        max=y;

    if(z>max)
        max=z;
    printf("%d",n-max);
}


#include<stdio.h>
int main()
{
    int n,a;
    scanf("%d",&n);
    long int i,arr[3]={0};
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        arr[a-1]++;
    }
    long max=0;
    for(i=0;i<3;i++) if(max<arr[i]) max=arr[i];
    printf("%ld",n-max);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,a=0,b=0,c=0,x,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x==1)a++;
        else if(x==2)b++;
        else  c++;
    }
    if(a>b&&a>c)printf("%d",b+c);
    else if(b>c&&b>a)printf("%d",a+c);
    else printf("%d",a+b);
    return 0;
}


#include <stdio.h>
int nain()
{
    int n,a=0,b=0,c=0,x,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x==1)a++;
        else if(x==2)b++;
        else  c++;
    }
    if(a>b&&a>c)printf("%d",b+c);
    else if(b>c&&b>a)printf("%d",a+c);
    else printf("%d",a+b);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,a=0,b=0,c=0,x,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x==1)a++;
        else if(x==2)b++;
        else  c++;
    }
    if(a>b&&a>c)printf("%d",b+c);
    else if(b>c&&b>a)printf("%d",a+c);
    else if(c>a&&c>b)printf("%d",a+b);
    else if(a==b&&b==c&&a==c) printf("%d",a+b);
    else if(a==b)printf("%d",c+a);
    else if(c==b)printf("%d",a+b);
    else if(a==c)printf("%d",a+b);
    else ;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(){
long int n;
scanf("%ld",&n);
int a=0,b=0,c=0,x;
while(n--){
    scanf("%d",&x);
    if (x==1){
        a++;
    }

    else if (x==2){
        b++;
    }

    else
        c++;
}

int min=a+b;

if (min>b+c){
    min=b+c;
}

if (min>c+a){
    min=c+a;
}

printf("%d",min);

return 0;
}


#include <assert.h>
#include <stdio.h>

int max(int a, int b, int c) {
    if (a >= b && a >= c)
        return a;
    else if (b >= a && b >= c)
        return b;
    else
        return c;
}

/*
 * http://codeforces.com/problemset/problem/52/A
 * A. 123-sequence
 */
int main(void) {
    int ok, n, x, uno, dos, tres, i;
    ok = scanf("%i", &n);
    assert(ok == 1 && 1 <= n && n <= 1000000);
    uno = 0;
    dos = 0;
    tres = 0;
    for (i = 0; i < n; ++i) {
        ok = scanf("%i ", &x);
        assert(ok == 1 && 1 <= x && x <= 3);
        if (x == 1)
            ++uno;
        else if (x == 2)
            ++dos;
        else
            ++tres;
    }
    printf("%i\n", n - max(uno, dos, tres));

    return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int main (void){
    unsigned long int n,i,c1=0,c2=0,c3=0,z,max;
    int num;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&num);
        if(num==1)
            c1++;
        else if (num==2)
            c2++;
        else if(num==3)
            c3++;
    }
    max = ( c1 > c2 )? c1 : c2;
    max = (max > c3) ? max : c3;
    z=n-max;
    printf("%d",z);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(){
  unsigned int n, i, a, max, numbers[] = {0, 0, 0, 0};

  scanf("%u", &n);
  for(i=0; i < n; i++){
    scanf("%d", &a);
    numbers[a]++;
  }

  max = numbers[0] > numbers[1] ? numbers[0] : numbers[1];
  max = numbers[2] > max ? numbers[2] : max;

  printf("%u\n", n - max);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(){
  unsigned int n, i, a, max, numbers[] = {0, 0, 0, 0};

  scanf("%u", &n);
  for(i=0; i < n; i++){
    scanf("%d", &a);
    numbers[a]++;
  }

  max = numbers[1] > numbers[2] ? numbers[1] : numbers[2];
  max = numbers[3] > max ? numbers[3] : max;

  printf("%u\n", n - max);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(){
  unsigned int n, i, a, max, numbers[] = {0, 0, 0};

  scanf("%u", &n);
  for(i=0; i < n; i++){
    scanf("%d", &a);
    numbers[a]++;
  }

  max = numbers[0] > numbers[1] ? numbers[0] : numbers[1];
  max = numbers[2] > max ? numbers[2] : max;

  printf("%u\n", n - max);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i;scanf("%d",&n);long long int a[n],p,k,x,y,z,ma;x=y=z=0;
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<n;i++)
    {
        if(a[i]==1)
            x++;
        if(a[i]==2)
            y++;
        if(a[i]==3)
            z++;
    }
    if(x>=y&&x>=z)
        ma=x;
    if(y>=x&&y>=z)
        ma=y;
    else
        ma=z;
    printf("%lld",n-ma);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i;scanf("%d",&n);long long int a[n],p,k,x,y,z,ma;x=y=z=0;
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<n;i++)
    {
        if(a[i]==1)
            x++;
        else if(a[i]==2)
            y++;
         else
            z++;
    }
    if(x>=y&&x>=z)
        ma=x;
    else if(y>=x&&y>=z)
        ma=y;
    else
        ma=z;
    printf("%lld",n-ma);
    //printf("%d",x);
    return 0;
}


#include<stdio.h>

int main()
{
    int n;
    int a,x=0,y=0,z=0;

    scanf("%d",&n);
    while(n--){
        scanf("%d",&a);
        if(a==1) x++;
        else if(a==2) y++;
        else z++;
    }
    if(x>=y&&x>=z) printf("%d",y+z);
    else if(y>=x&&y>=z) printf("%d",x+z);
    else printf("%d",x+y);

    return 0;
}


#include<stdio.h>
//#include<conio.h>
int main()
{
    long int n,s=0,a,i,w=0,x=0,y=0,z;
    scanf("%ld",&n);
    for(i=1;i<=n;i++)
    {  scanf("%ld",&a);
    if(a==1)  w++;  else if(a==2) x++;  else y++;  }
    z=(w>x?(w>y?w:y):(x>y?x:y));
    printf("%ld",w+x+y-z);
//    getch();
    return(0);
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
    long long int i,j=0,k=0,m=0,n,rem,div,val,big;

    scanf("%lld",&n);

    for(i=0;i<n;i++)
    {
        scanf("%lld",&val);
        if(val==1) j++; else if(val==2) k++;else m++;           //so j,k,m counts the number of 1,2,3 respectively

    }

   big=((j+k)+abs(j-k))/2;
    big=((big+m)+abs(big-m))/2;

    printf("%lld\n",n-big);
    return 0;
}


#include <stdio.h>

int main(int argc, char *argv[])
{
	unsigned long n,i=0;
	unsigned long count[3];
	int num;
	count[0]=count[1]=count[2]=0;
	scanf("%ld", &n);
	for(i=0; i<n; i++){
		scanf("%d", &num); count[num-1]++;
	}
	if(count[0]>=count[1] && count[0]>=count[2])
		printf("%ld", count[1]+count[2]);
	else if(count[1]>=count[0] && count[1]>=count[2])
		printf("%ld", count[0]+count[2]);
	else
		printf("%ld", count[0]+count[2]);
	return 0;
}


#include <stdio.h>

int main(int argc, char *argv[])
{
	unsigned long n,i=0;
	unsigned long count[3];
	int num;
	count[0]=count[1]=count[2]=0;
	scanf("%ld", &n);
	for(i=0; i<n; i++){
		scanf("%d", &num); count[num-1]++;
	}
	if(count[0]>=count[1] && count[0]>=count[2])
		printf("%ld", count[1]+count[2]);
	else if(count[1]>=count[0] && count[1]>=count[2])
		printf("%ld", count[0]+count[2]);
	else
		printf("%ld", count[0]+count[1]);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n,a=0,b=0,c=0,d;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&d);
        if (d==1) a++;
        if (d==2) b++;
        if (d==3) c++;
    }
    if (a>=b && a>=c) {printf("%d",b+c); return 0;}
     if (b>=a && b>=c) {printf("%d",a+c); return 0;}
      if (c>=b && c>=a) printf("%d",b+a );
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n,a=0,b=0,c=0,d;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&d);
        if (d==1) a++;
        if (d==2) b++;
        if (d==3) c++;
    }
    if (a>=b && a>=c) printf("%d",b+c);
     if (b>=a && b>=c) printf("%d",a+c);
      if (c>=b && c>=a) printf("%d",b+a );
    return 0;
}


#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],i,x=0,y=0,z=0;
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]==1)x++;
        if(a[i]==2)y++;
        if(a[i]==3)z++;
    }
    if(x>y&&x>z)printf("%d",n-x);
    else if(y>z&&y>x)printf("%d",n-y);
    else if(z>x&&z>y)printf("%d",n-z);
    return 0;
}


#include <stdio.h>

int min(int a, int b)
{
  return a<b ? a : b;
}

int main()
{
  int t[3] = {0, 0, 0}, n, m;
  scanf("%d", &n);
  while (n--) scanf("%d", &m), t[m-1]++;
  int a = t[0]+t[1], b = t[2]+t[1], c = t[0]+t[2];
  printf("%d\n", min(min(a, b), c));
  return 0;
}


#include <stdio.h>
int arr[4];
int main(){
   int n,d,maxi,in,i,sum=0;
   scanf("%d",&n);
   while(n--){
      scanf("%d",&d);
      arr[d]++;
   }
   maxi=arr[1];
   in = 1;
   for(i=1;i<=3;i++){
       if(arr[i]>maxi){
          maxi=arr[i];
          in = i;
       }
   }
   for(i=1;i<=3;i++)
     if(i!=in) sum+=arr[i];
   printf("%d",sum);
   return 0;
}


#include<stdio.h>

int main()
{long int i,n,d=0,b=0,c=0,min; int a;
scanf("%ld",&n);
for(i=0;i<n;i++)
 {scanf("%d",&a);
  if(a!=1) b++;
  if(a!=2) c++;
  if(a!=3) d++;
 }
min=d;
if(b<d && b<=c) min=b;
if(c<d && c<=b) min=c;
printf("%ld",min);

return 0;
}


#include <stdio.h>

#define min(x,y) ((x)<(y)?(x):(y))
int main(void) {
	int n, x[3];
	scanf("%d", &n);
	while (n--) {
		getchar();
		x[getchar() - '1']++;
	}
	printf("%d", min(x[0] + x[1], min(x[1] + x[2], x[0] + x[2])));
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,one=0,two=0,three=0;
    scanf("%d",&n);
    int ara[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&ara[i]);
        if(ara[i]==1)
            one++;
        else if(ara[i]==2)
            two++;
        else
            three++;
    }
    if(one>=two&&one>=three)
        printf("%d",n-one);
    else if(two>=one&&two>=three)
        printf("%d",n-two);
    else
        printf("%d",n-three);
    return 0;
}


#include <stdio.h>

int main()
{
    long long int n,i,s1,s2,s3,mx,one=0,two=0,three=0;

    scanf("%I64d",&n);

    int a;
    for(i=0;i<n;i++) {
        scanf("%d",&a);
        if(a==1)
            one++;
        if(a==2)
            two++;
        if(a==3)
            three++;
    }

    s1 = one+two;
    s2 = two+three;
    s3 = three+one;

    //printf("%I64d %I64d %I64d\n",s1,s2,s3);
    if(s1<s2)
        mx = s1;
    else
        mx = s2;
    if(mx>s3)
        mx = s3;

    printf("%I64d",mx);

}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,no,i,count_1=0,count_2=0,count_3=0;
	scanf("%d",&n);
//	int *a=(int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&no);
		if(no==1)
			count_1++;
		else if(no==2)
			count_2++;
		else
			count_3++;
	}
	if(count_1+count_2<count_2+count_3 && count_1+count_2<count_1+count_3)
		printf("%d\n",count_1+count_2);
	else if(count_2+count_3<count_1+count_2 && count_2+count_3<count_1+count_3)
		printf("%d\n",count_2+count_3);
	else if(count_1+count_3<count_2+count_3 && count_1+count_3<count_1+count_2)
		printf("%d\n",count_1+count_3);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,no,i,count_1=0,count_2=0,count_3=0;
	scanf("%d",&n);
//	int *a=(int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&no);
		if(no==1)
			count_1++;
		else if(no==2)
			count_2++;
		else
			count_3++;
	}
	if(count_1+count_2<=count_2+count_3 && count_1+count_2<=count_1+count_3)
		printf("%d\n",count_1+count_2);
	else if(count_2+count_3<=count_1+count_2 && count_2+count_3<=count_1+count_3)
		printf("%d\n",count_2+count_3);
	else if(count_1+count_3<=count_2+count_3 && count_1+count_3<=count_1+count_2)
		printf("%d\n",count_1+count_3);
	return 0;
}


#include <stdio.h>
#include <string.h>

int min(int a, int b) {
	return a < b ? a : b;
}

int main() {
	int n; scanf("%d", &n);

	int i, c[3];
	memset(c, 0, sizeof(c));
	for (i = 0; i < n; i++) {
		int a; scanf("%d", &a); a--;
		c[a]++;
	}

	printf("%d\n", min(c[0]+c[1], min(c[0]+c[2], c[1]+c[2])));

	return 0;
}


#include<stdio.h>
int main()
{
    int n,a[100000],i,p=0,q=0,r=0,max;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);

    }
    for(i=1; i<=n; i++)
    {
        if(a[i]==1)
            p++;
        else if(a[i]==2)
            q++;
        else r++;

    }
    if(p>q)
    {
        if(p>r)
        {
            max=p;
        }
        else
        {
            max=r;
        }
    }
    else
    {
        if(q>r)
        {
            max=q;
        }
        else
        {
            max=r;
        }
    }
printf("%d",n-max);}


#include<stdio.h>
int main()
{
    int n,a[100000],i,p=0,q=0,r=0,max;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);

    }
    for(i=0; i<n; i++)
    {
        if(a[i]==1)
            p++;
        else if(a[i]==2)
            q++;
        else r++;

    }
    if(p>q)
    {
        if(p>r)
        {
            max=p;
        }
        else
        {
            max=r;
        }
    }
    else
    {
        if(q>r)
        {
            max=q;
        }
        else
        {
            max=r;
        }
    }
printf("%d",n-max);}


#include<stdio.h>
int main()
{
    int n,a[1000005],i,max;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);

    }
    int p=0,q=0,r=0;
    for(i=0; i<n; i++)
    {
        if(a[i]==1)
            p++;
        else if(a[i]==2)
            q++;
        else r++;

    }
    if(p>q)
    {
        if(p>r)
        {
            max=p;
        }
        else
        {
            max=r;
        }
    }
    else
    {
        if(q>r)
        {
            max=q;
        }
        else
        {
            max=r;
        }
    }
printf("%d",n-max);
return 0;}


#include<stdio.h>
int main()
{
    int n,a[100000],i,p=0,q=0,r=0,max;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);

    }
    for(i=0; i<n; i++)
    {
        if(a[i]==1)
            p++;
        else if(a[i]==2)
            q++;
        else r++;

    }
    if(p>q)
    {
        if(p>r)
        {
            max=p;
        }
        else
        {
            max=r;
        }
    }
    else
    {
        if(q>r)
        {
            max=q;
        }
        else
        {
            max=r;
        }
    }
printf("%d",n-max);
return 0;}


#include <stdio.h>

int main()
{
    int n,a,i,ara[1000005],max;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
    }
    int count1=0,count2=0,count3=0;
    for(i=0;i<n;i++){
        if(ara[i]==1){
            count1++;
        }
        else if(ara[i]==2){
            count2++;
        }
        else{
            count3++;
        }
    }
    if(count1>count2){
        if(count1>count3){
            max=count1;
        }
        else{
            max=count3;
        }
    }
    else{
        if(count2>count3){
            max=count2;
        }
        else{
            max=count3;
        }
    }
    printf("%d\n",n-max);

    return 0;
}


#include<stdio.h>
int main()
{
    int n,a[100000],i,p=0,q=0,r=0,max;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);

    }
    for(i=0; i<n; i++)
    {
        if(a[i]==1)
            p++;
        else if(a[i]==2)
            q++;
        else r++;

    }
    if(p>q)
    {
        if(p>r)
        {
            max=p;
        }
        else
        {
            max=r;
        }
    }
    else
    {
        if(q>r)
        {
            max=q;
        }
        else
        {
            max=r;
        }
    }
printf("%d",n-max);}


#include<stdio.h>
int main()
{
    int n,a[100000],i,max;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);

    }
    int p=0,q=0,r=0;
    for(i=0; i<n; i++)
    {
        if(a[i]==1)
            p++;
        else if(a[i]==2)
            q++;
        else r++;

    }
    if(p>q)
    {
        if(p>r)
        {
            max=p;
        }
        else
        {
            max=r;
        }
    }
    else
    {
        if(q>r)
        {
            max=q;
        }
        else
        {
            max=r;
        }
    }
printf("%d",n-max);
return 0;}


#include<stdio.h>
int main()
{
int a,i,p=0,q=0,r,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%d",&a);
 if(a==1) p++;
else if(a==2) q++;
}
r=n-(p+q);
if(p<q) p=q;
if(p<r) p=r;
printf("\n%d",n-p);
return(0);

}


#include<stdio.h>
#include<string.h>

 main(){
 int i,j,k,l,a=0,b,m,n;

 scanf("%d",&n);

 for(i=1;i<=n;i++){
    scanf("%d",&a);
    scanf("%d",&b);

    if(a<b){
    printf("%d\n",b-a);

            }

    if(a==b){
        printf("0\n");

    }

    if(a>b){
        if((a-b)%2==0){
            printf("1\n");

        }
        else if((a-b)%2!=0){
            printf("2\n");

        }
        }
        continue;

}

 }


#include<bits\stdc++.h>
using namespace std;
int main()
{
int a,b,t; cin>>t;
while(t--)
{
 cin>>a>>b;
 if(a==b) cout<<0<<endl;
 else if((a<b && (a-b)%2)||(a>b &&(a-b)%2==0)) cout<<1<<endl;
 else cout<<2<<endl;
}
}


int main()
{
int a,b,t; cin>>t;
while(t--)
{
 cin>>a>>b;
 if(a==b) cout<<0<<endl;
 else if((a<b && (a-b)%2)||(a>b &&(a-b)%2==1)) cout<<1<<endl;
 else cout<<2<<endl;
}
}


#include<bits\stdc++.h>
using namespace std;
int main()
{
int a,b,t; cin>>t;
while(t--)
{
 cin>>a>>b;
 if(a==b) cout<<0<<endl;
 else if((a<b && (a-b)%2)||(a>b &&(a-b)%2==0) cout<<1<<endl;
 else cout<<2<<endl;
}
}


#include<bits\stdc++.h>
using namespace std;
int main()
{
int a,b,t; cin>>t;
while(t--)
{
 cin>>a>>b;
 if(a==b) cout<<0<<endl;
 else if((a<b && (a-b)%2)||(a>b &&(a-b)%2==1)) cout<<1<<endl;
 else cout<<2<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,a,b,c;
	cin>>t;
	while(t--)
	{
		cin>>a>>b;
		c=a-b;
		if(c>0)
		{
			if(c%2!=0)//odd
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		if(c<0)
		{
			if(c%2==0)
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		if(c==0)
		{
			cout<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,a,b,c;
	cin>>t;
	while(t--)
	{
		cin>>a>>b;
		c=b-a;
		if(c>0)
		{
			if(c%2!=0)//odd
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		if(c<0)
		{
			if(c%2==0)
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		if(c==0)
		{
			cout<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,a,b,c;
	cin>>t;
	while(t--)
	{
		cin>>a>>b;
		c=a-b;
		if(c>0)
		{
			if(c%2!=0)//odd
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		if(c<0)
		{
			if(c%2==0)
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		if(c==0)
		{
			cout<<0endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,a,b,c;
	cin>>t;
	while(t--)
	{
		cin>>a>>b;
		c=b-a;
		if(c>0)
		{
			if(c%2!=0)//odd
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		if(c<0)
		{
			if(c%2==0)
				cout<<1<<endl;
			else
				cout<<2<<endl;
		}
		if(c==0)
		{
			cout<<0<<endl;
		}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while(t--) {
		int a, b;
		cin >> a >> b;
		if(a==b)
			cout << "0\n";
		else if((a&1)^(b&1)&&a<b)
			cout << "1\n";
		else if((a&1)==(b&1)&&a>b)
			cout << "1\n";
		else
			cout << "2\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(a==b)cout<<"0\n";
    else
    if((a&1)==(b&1)&&a>b)cout<<"1\n";
    else
    if((a&1)!=(b&1)&&a<b)cout<<"1\n";
    else
    cout<<"2\n";
}

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(a==b)cout<<0;
    if(a%2!=b%2&&a>b)cout<<2;
    if(a%2==b%2&&a>b)cout<<1;
    if(a%2!=b%2&&a<b)cout<<1;
    if(a%2==b%2&&a<b)cout<<2;
}
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(a==b)cout<<"0\n";
    if((a&1)!=(b&1)&&a>b)cout<<"2\n";
    if((a&1)==(b&1)&&a>b)cout<<"1\n";
    if((a&1)!=(b&1)&&a<b)cout<<"1\n";
    if((a&1)==(b&1)&&a<b)cout<<"2\n";
}

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll  t;
  cin>>t;
  while(t--)
  {
      ll a,b;
      cin>>a>>b;
      if(a>b)
      {
          if((a-b)%2==0)
          cout<<1<<endl;
          else
          cout<<2<<endl;
      }
      else if(b>a)
      {
          if((b-a)%2==1)
          cout<<1<<endl;
          else
          cout<<2<<endl;
      }
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int;
int main()
{
  ll  t;
  cin>>t;
  while(t--)
  {
      ll a,b;
      cin>>a>>b;
      if(a>b)
      {
          if((a-b)%2==0)
          cout<<1<<endl;
          else
          cout<<2<<endl;
      }
      else if(b>a)
      {
          if((b-a)%2==1)
          cout<<1<<endl;
          else
          cout<<2<<endl;
      }
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int;
int main()
{
  ll  t;
  cin>>t;
  while(t--)
  {
      ll a,b;
      cin>>a>>b;
      if(a>b)
      {
          if((a-b)%2==0)
          cout<<1<<endl;
          else
          cout<<2<<endl;
      }
      else if(b>a)
      {
          if((b-a)%2==1)
          cout<<1<<endl;
          else
          cout<<2<<endl;
      }
      else
      cout<<0<<endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll  t;
  cin>>t;
  while(t--)
  {
      ll a,b;
      cin>>a>>b;
      if(a>b)
      {
          if((a-b)%2==0)
          cout<<1<<endl;
          else
          cout<<2<<endl;
      }
      else if(b>a)
      {
          if((b-a)%2==1)
          cout<<1<<endl;
          else
          cout<<2<<endl;
      }
      else
      cout<<0<<endl;
  }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define clr(v,d) memset(v,d,sizeof(v))
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
//#define x first
//#define y second
#define point pair<int,int>

int maximiz(int dish[], int mask, int cnt){
    if(mask == 8)
        return cnt;
    int a=mask%2, b=(mask%4)/2, c=(mask%8)/4;
    //take
    if(dish[0] - a >= 0 && dish[1]- b >= 0 && dish[2] - c >= 0){
        int dish2[]={dish[0] - a, dish[1]-b, dish[2]-c};
        return max(maximiz(dish,mask+1, cnt), maximiz(dish2,mask+1,cnt+1));
    }
    else
        return maximiz( dish,  mask+1, cnt);
}

int main() {
    //freopen("dream.in" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);\

    int t; scanf("%d",&t);
    while(t--){
        int a,b;
        scanf("%d %d",&a, &b);
        int ans;
        if(a <= b) ans= b-a;
        else{
            ans=((a-b)%2)+1;
        }

        printf("%d\n", ans);
    }

}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define clr(v,d) memset(v,d,sizeof(v))
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
//#define x first
//#define y second
#define point pair<int,int>

int maximiz(int dish[], int mask, int cnt){
    if(mask == 8)
        return cnt;
    int a=mask%2, b=(mask%4)/2, c=(mask%8)/4;
    //take
    if(dish[0] - a >= 0 && dish[1]- b >= 0 && dish[2] - c >= 0){
        int dish2[]={dish[0] - a, dish[1]-b, dish[2]-c};
        return max(maximiz(dish,mask+1, cnt), maximiz(dish2,mask+1,cnt+1));
    }
    else
        return maximiz( dish,  mask+1, cnt);
}

int main() {
    //freopen("dream.in" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    //cin.tie(0);
    //cin.sync_with_stdio(0);\

    int t; scanf("%d",&t);
    while(t--){
        int a,b;
        cin>>a>>b;
        int ans;
        if(a <= b) ans= b-a;
        else{
            ans=((a-b)%2)+1;
        }

        cout<<ans<<'\n';
    }

}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define clr(v,d) memset(v,d,sizeof(v))
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
//#define x first
//#define y second
#define point pair<int,int>

int maximiz(int dish[], int mask, int cnt){
    if(mask == 8)
        return cnt;
    int a=mask%2, b=(mask%4)/2, c=(mask%8)/4;
    //take
    if(dish[0] - a >= 0 && dish[1]- b >= 0 && dish[2] - c >= 0){
        int dish2[]={dish[0] - a, dish[1]-b, dish[2]-c};
        return max(maximiz(dish,mask+1, cnt), maximiz(dish2,mask+1,cnt+1));
    }
    else
        return maximiz( dish,  mask+1, cnt);
}

int main() {
    //freopen("dream.in" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);\

    int t; scanf("%d",&t);
    while(t--){
        int a,b; cin>>a>>b;
        int ans;
        if(a <= b) ans= b-a;
        else{
            ans=((a-b)%2)+1;
        }

        cout<<ans<<'\n';
    }

}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define clr(v,d) memset(v,d,sizeof(v))
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
//#define x first
//#define y second
#define point pair<int,int>

int maximiz(int dish[], int mask, int cnt){
    if(mask == 8)
        return cnt;
    int a=mask%2, b=(mask%4)/2, c=(mask%8)/4;
    //take
    if(dish[0] - a >= 0 && dish[1]- b >= 0 && dish[2] - c >= 0){
        int dish2[]={dish[0] - a, dish[1]-b, dish[2]-c};
        return max(maximiz(dish,mask+1, cnt), maximiz(dish2,mask+1,cnt+1));
    }
    else
        return maximiz( dish,  mask+1, cnt);
}

int main() {
    //freopen("dream.in" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    //cin.tie(0);
    //cin.sync_with_stdio(0);\

    int t; scanf("%d",&t);
    while(t--){
        int a,b;
        scanf("%d %d", &a, &b);
        int ans;
        if(a== b) ans=0;
        else if(a < b){
            ans=1+ !((b-a)%2);
        }
        else{
            ans=((a-b)%2)+1;
        }

        printf("%d\n",ans);
    }

}


#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>

using namespace std;

int main()
{
    long long int  i , n  , mi = 0 , k , m , t , q = 0 , a[100] , b[100] , x[100] , y[100] , c = 0 , d = 2 ;
 	string s , z ;

 	cin >> n ;

 	for(k = 0 ; k < n ; k++){

 		cin >> m >> t ;

 		if(m==t){
 			cout << "0" << endl;
 		}
 		else if(m < t){

 			k = t - m ;

 			if(k%2!=0){
 				cout << "1" << endl ;
 			}
 			else{
 				cout << "2" << endl ;
 			}
 		}
 		else {
 			k = m - t ;
 			if(k%2!=0){
 				cout << "2" << endl ;
 			}
 			else{
 				cout << "1" << endl ;
 			}

 		}
 	}
  return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>

using namespace std;

int main()
{
    long long int  i , n , k , m , t ;

 	cin >> n ;

 	for(k = 0 ; k < n ; k++){

 		cin >> m >> t ;

 		if(m==t){
 			cout << "0" << endl;
 		}
 		else if(m < t){

 			k = t - m ;

 			if(k%2!=0){
 				cout << "1" << endl ;
 			}
 			else{
 				cout << "2" << endl ;
 			}
 		}
 		else if(m > t){
 			k = m - t ;
 			if(k%2!=0){
 				cout << "2" << endl ;
 			}
 			else{
 				cout << "1" << endl ;
 			}

 		}
 	}
  return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>

using namespace std;

int main()
{
    long long int  i , n , x , k , m , t ;

 	cin >> n ;

 	for(x = 0 ; x < n ; x++){

 		cin >> m >> t ;

 		if(m==t){
 			cout << "0" << endl;
 		}
 		else if(m < t){

 			k = t - m ;

 			if(k%2!=0){
 				cout << "1" << endl ;
 			}
 			else{
 				cout << "2" << endl ;
 			}
 		}
 		else if(m > t){
 			k = m - t ;
 			if(k%2!=0){
 				cout << "2" << endl ;
 			}
 			else{
 				cout << "1" << endl ;
 			}

 		}
 	}
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--){
        int a,b;
        cin >> a >> b;
        int dem=0;
        if(a<=b){
            if((b-a)%2!=0) cout << 1 <<endl;
            else cout << b-a <<endl;
        }
        else{
            if((a-b)%2==0) cout << 1 <<endl;
            else{
                cout << 2 <<endl;
            }
        }
    }
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--){
        int a,b;
        cin >> a >> b;
        int dem=0;
        if(a<=b) cout << b-a <<endl;
        else{
            if((a-b)%2==0) cout << 1 <<endl;
            else cout << 2 <<endl;
        }
    }
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--){
        int a,b;
        cin >> a >> b;
        int dem=0;
        if(a<b){
            if((b-a)%2!=0) cout << 1 <<endl;
            else cout << 2 <<endl;
        }
        else if(a==b) cout << 0 <<endl;
        else{
            if((a-b)%2==0) cout << 1 <<endl;
            else{
                cout << 2 <<endl;
            }
        }
    }
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--){
        int a,b;
        cin >> a >> b;
        int dem=0;
        if(a<b) cout << 1 <<endl;
        else if(a==b) cout << 0 <<endl;
        else{
            if((a-b)%2==0) cout << 1 <<endl;
            else{
                cout << 2 <<endl;
            }
        }
    }
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        int a,b;
        cin>>a>>b;
        if(a>=b){
            d = a-b;
            if(d&1){
                cout<<2<<"\n";
            }
            else{
                cout<<1<<"\n";
            }
        }
        else{
            d = b-a;
            if(d&1){
                cout<<1<<"\n";
            }
            else{
                cout<<2<<"\n";
            }
        }
    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        int a,b;
        cin>>a>>b;
        if(a>=b){
            int d = a-b;
            if(d&1){
                cout<<2<<"\n";
            }
            else{
                cout<<1<<"\n";
            }
        }
        else{
            int d = b-a;
            if(d&1){
                cout<<1<<"\n";
            }
            else{
                cout<<2<<"\n";
            }
        }
    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        int a,b;
        cin>>a>>b;
        if(a==b){
            cout<<0<<"\n";
        }
        else if(a>b){
            int d = a-b;
            if(d&1){
                cout<<2<<"\n";
            }
            else{
                cout<<1<<"\n";
            }
        }
        else{
            int d = b-a;
            if(d&1){
                cout<<1<<"\n";
            }
            else{
                cout<<2<<"\n";
            }
        }
    }
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        int a,b;
        cin>>a>>b;
        if(a>=b){
            int d = a-b;
            if(d&1){
                cout<<2<<"\n";
            }
            else{
                cout<<1<<"\n";
            }
        }
        else{
            d = b-a;
            if(d&1){
                cout<<1<<"\n";
            }
            else{
                cout<<2<<"\n";
            }
        }
    }
}


#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <list>
#include <string>

using namespace std;

/*list<int> adj[2000];
bool visited[2000] = {};
//int distance[2000]; // Initialize distance[i] = infinity for all i
//int parent[2000]; // Initialize parent[i] = -1 for all i
queue<int> q;

int bfs(int source){
	int height=0;
//distance[source] = 0;
//parent[source] = -1;
visited[source] = true;
q.push(source);
int c=0;
while (!q.empty()) {
	int v = q.front();
	q.pop();
	if(c){
		c--;

	}
	for(int u : adj[v]) {
		if (!visited[u]) {
			//distance[u] = distance[v] + 1;
			//parent[u] = v;
			visited[u] = true;
			q.push(u);
		}
	}
	if(c==0&&!q.empty()){
		c=q.size();
		height++;
	}
}
return height;
}*/
/*void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

     create temp arrays
    int L[n1], R[n2];

     Copy data to temp arrays L[] and R[]
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

     Merge the temp arrays back into arr[l..r]
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

     Copy the remaining elements of L[], if there
       are any
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

     Copy the remaining elements of R[], if there
       are any
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

 l is for left index and r is right index of the
   sub-array of arr to be sorted
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}*/
int main(){
	int t;
	cin >>t;
/*	for(int i=0;i<t;i++){
		int n;
		cin >>n;
		string s;
		int arr[n];
		for(int j=0;j<n;j++){
			cin>>s>>arr[j];
		}
		mergeSort(arr,0,n-1);
		int res=0;
		for(int k=0;k<n;k++){
			res+=abs(k+1-arr[k]);
		}

		cout<<res<<endl;
	}*/
	for(int i=0;i<t;i++){
		int a,b;
		cin >>a>>b;
		if(a-b==0){
			cout<<"0"<<endl;
		}else if((a-b)%2==0&&b>a){
			cout<<"2"<<endl;
		}else if((a-b)%2==0&&a>b){
			cout<<"1"<<endl;
		}else if((b-a)==1){
			cout<<"1"<<endl;
		}else if((a-b)==1){
			cout<<"2"<<endl;
		}
		else if((a-b)%2==1&&b>a){
			cout<<"1"<<endl;
		}else if((a-b)%2==1&&a>b){
			cout<<"2"<<endl;
		}

	}
	return 0;

}


#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <list>
#include <string>

using namespace std;

/*list<int> adj[2000];
bool visited[2000] = {};
//int distance[2000]; // Initialize distance[i] = infinity for all i
//int parent[2000]; // Initialize parent[i] = -1 for all i
queue<int> q;

int bfs(int source){
	int height=0;
//distance[source] = 0;
//parent[source] = -1;
visited[source] = true;
q.push(source);
int c=0;
while (!q.empty()) {
	int v = q.front();
	q.pop();
	if(c){
		c--;

	}
	for(int u : adj[v]) {
		if (!visited[u]) {
			//distance[u] = distance[v] + 1;
			//parent[u] = v;
			visited[u] = true;
			q.push(u);
		}
	}
	if(c==0&&!q.empty()){
		c=q.size();
		height++;
	}
}
return height;
}*/
/*void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

     create temp arrays
    int L[n1], R[n2];

     Copy data to temp arrays L[] and R[]
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

     Merge the temp arrays back into arr[l..r]
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

     Copy the remaining elements of L[], if there
       are any
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

     Copy the remaining elements of R[], if there
       are any
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

 l is for left index and r is right index of the
   sub-array of arr to be sorted
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}*/
int main(){
	int t;
	cin >>t;
/*	for(int i=0;i<t;i++){
		int n;
		cin >>n;
		string s;
		int arr[n];
		for(int j=0;j<n;j++){
			cin>>s>>arr[j];
		}
		mergeSort(arr,0,n-1);
		int res=0;
		for(int k=0;k<n;k++){
			res+=abs(k+1-arr[k]);
		}

		cout<<res<<endl;
	}*/
	for(int i=0;i<t;i++){
		int a,b;
		cin >>a>>b;
		if(a-b==0){
			cout<<"0"<<endl;
		}else if((a-b)%2==0&&b>a){
			cout<<"2"<<endl;
		}else if((a-b)%2==0&&a>b){
			cout<<"1"<<endl;
		}else if((b-a)==1){
			cout<<"1"<<endl;
		}else if((a-b)==1){
			cout<<"2"<<endl;
		}
		else if((a-b)%2==1&&b>a){
			cout<<"3"<<endl;
		}else if((a-b)%2==1&&a>b){
			cout<<"2"<<endl;
		}

	}
	return 0;

}


#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <list>
#include <string>

using namespace std;

/*list<int> adj[2000];
bool visited[2000] = {};
//int distance[2000]; // Initialize distance[i] = infinity for all i
//int parent[2000]; // Initialize parent[i] = -1 for all i
queue<int> q;

int bfs(int source){
	int height=0;
//distance[source] = 0;
//parent[source] = -1;
visited[source] = true;
q.push(source);
int c=0;
while (!q.empty()) {
	int v = q.front();
	q.pop();
	if(c){
		c--;

	}
	for(int u : adj[v]) {
		if (!visited[u]) {
			//distance[u] = distance[v] + 1;
			//parent[u] = v;
			visited[u] = true;
			q.push(u);
		}
	}
	if(c==0&&!q.empty()){
		c=q.size();
		height++;
	}
}
return height;
}*/
/*void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

     create temp arrays
    int L[n1], R[n2];

     Copy data to temp arrays L[] and R[]
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

     Merge the temp arrays back into arr[l..r]
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

     Copy the remaining elements of L[], if there
       are any
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

     Copy the remaining elements of R[], if there
       are any
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

 l is for left index and r is right index of the
   sub-array of arr to be sorted
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}*/
int main(){
	int t;
	cin >>t;
/*	for(int i=0;i<t;i++){
		int n;
		cin >>n;
		string s;
		int arr[n];
		for(int j=0;j<n;j++){
			cin>>s>>arr[j];
		}
		mergeSort(arr,0,n-1);
		int res=0;
		for(int k=0;k<n;k++){
			res+=abs(k+1-arr[k]);
		}

		cout<<res<<endl;
	}*/
	for(int i=0;i<t;i++){
		int a,b;
		cin >>a>>b;
		if(a-b==0){
			cout<<"0"<<endl;
		}else if((b-a)%2==0&&b>a){
			cout<<"2"<<endl;
		}else if((a-b)%2==0&&a>b){
			cout<<"1"<<endl;
		}else if((b-a)==1){
			cout<<"1"<<endl;
		}else if((a-b)==1){
			cout<<"2"<<endl;
		}
		else if((b-a)%2==1&&b>a){
			cout<<"1"<<endl;
		}else if((a-b)%2==1&&a>b){
			cout<<"2"<<endl;
		}

	}

	return 0;

}


#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <list>
#include <string>

using namespace std;

/*list<int> adj[2000];
bool visited[2000] = {};
//int distance[2000]; // Initialize distance[i] = infinity for all i
//int parent[2000]; // Initialize parent[i] = -1 for all i
queue<int> q;

int bfs(int source){
	int height=0;
//distance[source] = 0;
//parent[source] = -1;
visited[source] = true;
q.push(source);
int c=0;
while (!q.empty()) {
	int v = q.front();
	q.pop();
	if(c){
		c--;

	}
	for(int u : adj[v]) {
		if (!visited[u]) {
			//distance[u] = distance[v] + 1;
			//parent[u] = v;
			visited[u] = true;
			q.push(u);
		}
	}
	if(c==0&&!q.empty()){
		c=q.size();
		height++;
	}
}
return height;
}*/
/*void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

     create temp arrays
    int L[n1], R[n2];

     Copy data to temp arrays L[] and R[]
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

     Merge the temp arrays back into arr[l..r]
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

     Copy the remaining elements of L[], if there
       are any
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

     Copy the remaining elements of R[], if there
       are any
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

 l is for left index and r is right index of the
   sub-array of arr to be sorted
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}*/
int main(){
	int t;
	cin >>t;
/*	for(int i=0;i<t;i++){
		int n;
		cin >>n;
		string s;
		int arr[n];
		for(int j=0;j<n;j++){
			cin>>s>>arr[j];
		}
		mergeSort(arr,0,n-1);
		int res=0;
		for(int k=0;k<n;k++){
			res+=abs(k+1-arr[k]);
		}

		cout<<res<<endl;
	}*/
	for(int i=0;i<t;i++){
		int a,b;
		cin >>a>>b;
		if(a-b==0){
			cout<<"0"<<endl;
		}else if((a-b)%2==0&&a>b){
			cout<<"2"<<endl;
		}else if((a-b)%2==0&&b>a){
			cout<<"1"<<endl;
		}else if((a-b)%2==1&&a>b){
			cout<<"1"<<endl;
		}else if((a-b)%2==1&&b>a){
			cout<<"2"<<endl;
		}

	}
	return 0;

}


#include <iostream>
using namespace std;

int main() {
	int t,a,b,x,y,ans;
	cin >> t;
	while(t--) {
		ans = 0;
		cin >> a >> b;
		int sub = b-a;
		if (sub >= 0) {
			if (sub == 0) ans = 0;
			else if (sub%2 !=0) {
				if (a%2==0) ans = 1;
				else ans=2;
			} else {
				if (a % 2 == 0) ans = 2;
				else ans = 1;
			}
		} else {
			if (sub%2 !=0) {
				if (a%2==0) ans = 1;
				else ans = 2;
			} else {
				if (a%2==0) ans = 2;
				else ans = 1;
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t,a,b,x,y,ans;
	cin >> t;
	while(t--) {
		ans = 0;
		cin >> a >> b;
		int sub = b-a;
		if (sub >= 0) {
			if (sub == 0) ans = 0;
			else if (sub%2 !=0) {
				if (a%2==0) ans = 1;
				else ans=2;
			} else {
				if (a % 2 == 0) ans = 2;
				else ans = 1;
			}
		} else {
			if (sub%2 !=0) {
				if (a%2==0) ans = 2;
				else ans = 1;
			} else {
				if (a%2==0) ans = 1;
				else ans = 2;
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t,a,b,x,y,ans;
	cin >> t;
	while(t--) {
		ans = 0;
		cin >> a >> b;
		int sub = b-a;
		if (sub >= 0) {
			if (sub == 0) ans = 0;
			else if (sub%2 !=0) {
				if (a%2==0) ans = 1;
				else ans=2;
			} else {
				if (a % 2 == 0) ans = 2;
				else ans = 1;
			}
		} else {
			if (sub%2 !=0) ans = 2;
			else ans = 1;
		}
		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t,a,b,x,y,ans;
	cin >> t;
	while(t--) {
		ans = 0;
		cin >> a >> b;
		int sub = b-a;
		if (a == b) ans = 0;
		else {
			if (b > a) {
				if (a % 2 == 0 and b %2 == 0) ans = 2;
				if (a % 2 == 0 and b %2 != 0) ans = 1;
				if (a % 2 != 0 and b %2 == 0) ans = 1;
				if (a % 2 != 0 and b %2 != 0) ans = 2;
			} else {
				if (a % 2 == 0 and b %2 == 0) ans = 1;
				if (a % 2 == 0 and b %2 != 0) ans = 2;
				if (a % 2 != 0 and b %2 == 0) ans = 2;
				if (a % 2 != 0 and b %2 != 0) ans = 1;
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a, b;
	for(int i=0; i<n; i++){
		cin>>a;
		cin>>b;
		if(a==b)
			cout<<"0";
		else if(a<b){
			if((b-a)%2==0)
				cout<<"2";
			else
				cout<<"1";
		}
		else{
			if((a-b)%2==1)
				cout<<"2";
			else
				cout<<"1";
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int arr[2];
	int ctr;
	int jumlah;
	for(int i=0; i<n; i++){
		cin>>arr[0];
		cin>>arr[1];
		ctr = 0;
		jumlah = 0;
		while(arr[0]!=arr[1]){
			if(arr[0]>arr[1]){
				jumlah = arr[0]-arr[1];
				if(jumlah%2==0){
					ctr++;
					arr[0]= arr[1];
				}
				else{
					ctr = ctr + 2;
					arr[0]= arr[1];
				}
			}
			else if(arr[0]<arr[1]){
				jumlah = arr[1]-arr[0];
				if(jumlah%2==1){
					ctr++;
					arr[0]= arr[1];
				}
				else{
					ctr += 2;
					arr[0]= arr[1];
				}
			}
		}
		cout<<ctr<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int arr[2];
	int ctr;
	int jumlah;
	for(int i=0; i<n; i++){
		cin>>arr[0];
		cin>>arr[1];
		ctr = 0;
		jumlah = 0;
		while(arr[0]!=arr[1]){
			if(arr[0]>arr[1]){
				jumlah = arr[0]-arr[1];
				if(jumlah%2==0){
					ctr++;
					arr[0]= arr[1];
				}
				else{
					ctr = ctr + 2;
					arr[0]= arr[1];
				}
			}
			else if(arr[0]<arr[1]){
				jumlah = arr[1]-arr[0];
				if(jumlah%2==1){
					ctr++;
					arr[0]= arr[1];
				}
				else{
					ctr = ctr + 2;
					arr[0]= arr[1];
				}
			}
		}
		cout<<ctr<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a, b;
	for(int i=0; i<n; i++){
		cin>>a;
		cin>>b;
		if(a==b)
			cout<<"0";
		else if(a<b){
			if((b-a)%2==0)
				cout<<"2";
			else
				cout<<"1";
		}
		else{
			if((a-b)%2==0)
				cout<<"1";
			else
				cout<<"2";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin>>t;
  while(t--){
    long long int a,b;
    cin>>a>>b;
    if(a==b) cout<<0<<endl;
    else if(a>b){
      if(abs(a-b)%2==1) cout<<2<<endl;
      else cout<<1<<endl;
    }
    else{
      if(abs(a-b%2)==1) cout<<1<<endl;
      else cout<<2<<endl;
    }
  }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin>>t;
  while(t--){
    int n,m;
  cin>>n>>m;
  int a[n+1],p[n+1];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  memset(p,0,sizeof(p));
  for(int i=0;i<m;i++){
    int num;
    cin>>num;
    p[num-1]=1;
  }

  int check=0;
  for(int i=0;i<n-1;i++){
    for(int j=0;j<n-i-1;j++){
      if(a[j]>a[j+1]){
        if(p[j]!=0){
          swap(a[j],a[j+1]);
        }
        else if(p[j]==0){
          check=1;
          break;
        }
      }
    }
  }
  if(check==1) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  }
}