n = int(input())
a = list(map(int, input().split()))

s = sum(a)
for i in range(int(input())):
    b, c = map(int, input().split())
    for j in range(n):
        if a[j] == b:
            s -= b
            a[j] = c
            s += c
    print(s)