n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
    b,c = map(int, input().split())
    ans = 0
    for j in range(len(a)):
        if a[j] == b:
            a[j] = c
            ans += c
        else:
            ans += a[j]
    print(sum(a))