n = int(input())
a = str(input())
q = int(input())
s = []

for i in range(q):
    b,c = map(int,input().split())
    a = [c if j == b else j for j in a]
    s.append(sum(a))

for k in range(q):
    print(s[k])