n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = [list(map(int,input().split()))]
for i in range(q - 1):
    b.append(list(map(int,input().split())))

for i in range(q):
    a.sort()
    j = b[i][0]
    k = b[i][1]
    if j in a:
        for i in range(n):
            if a[i] <= j:
                if a[i] == j:
                    a[i] = k
            else:
                break
        print(sum(a))
    else:
        print(sum(a))