n = int(input())
alist = list(map(int,input().split()))
alist.sort()
ssum = sum(alist)
q = int(input())
for i in range(q):
    b,c = map(int,input().split())
    x = 0
    for j in range(n):
        if alist[j] == b:
            x = 1
            alist[j] = c
            ssum = ssum-b+c
        elif x == 1 and alist[j] != b:
            break
    print(ssum)