
#=input()
n=int(input())
#=map(int,input().split())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for _ in range(q)]

for i in range(q):
    w = bc[i][0]
    e = bc[i][1]
    a = [e if j==w else j for j in a]
    sum = 0
    for k in range(n):
        sum += a[k]
    print(sum)