n = int(input())
a = list(map(int, input().split()))
q = int(input())
b=[]
c=[]
for j in range(q):
    b1, c1 = map(int,input().split())
    b.append(b1)
    c.append(c1)
for i in range(q):
    for h in range(n): 
        if b[i] == a[h]:
            a[h] = c[i]
    print(sum(a))