n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
    b, c, = map(int, input().split())
    while b in a:
        ind = a.index(b)
        a[ind] = c
    print(sum(a))