x=int(input())

y=[int(i) for i in input().split()]

z=int(input())

for i in range(z):
    a, b= map(int , input().split())
    v=[]
    for ele in y:
        if ele == a:
            v.append(b)
        else:
            v.append(ele)

    sum1 = 0
    for ele in v:
        sum1 += ele
    y=v
    print(sum1)