N = int(input())
l = 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 l[j] == B:
            l[j] = C
    print(sum(l))