N = int(input())
A = list(map(int,input().split(" ")))
Q = int(input())
B = [list(map(int,input().split(" "))) for i in range(0,Q)]

for i in range(0,Q):
    index = [j for j, x in enumerate(A) if x == B[i][0]]
    for j in index:
        A[j] = B[i][1]
    print(sum(A))
#print("\n".join(list(map(str,A.tolist()))))