N = int(input())
a = list(map(int,input().split()))
Q = int(input())


for i in range(Q):
    B,C = map(int, input().split())
    for j in range(N):
        if a[j] == B:
            a[j] = C
    print(sum(a))
