# -*- coding: utf-8 -*-

import copy

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

B = []
C = []
for _ in range(Q):
    B_i, C_i = map(int, input().split())
    
    B.append(B_i)
    C.append(C_i)

for q in range(Q):
    indexes = [i for i, a in enumerate(A) if a == B[q]]
    for i in indexes:
        A[i] = C[q]
        
    print(sum(A), flush=True)
