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:
        s = a.index(b)
        a[s] = c

    print(sum(a))