N = int(input())
lsn = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    b, c = map(int, input().split())
    for i in range(len(lsn)):
        if lsn[i] == b:
            lsn[i] = c
    print(sum(lsn))