n = int(input())
a = list(map(int, input().split()))
q = int(input())
for j in range(q):
    B, C = map(int, input().split())
    for n, i in enumerate(a):
        if i == B:
            a[n] = C
    print(sum(a))