N = int(input())
A = list(map(int, input().split()))
A.sort()
Q = int(input())
B = []
C = []

for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(Q):
    s = 0
    e = N
    h = int((s+e)/2)
    while A[h] != B[i] and s != h :
        if A[h] < B[i]:
            s = h
            h = int((s+e)/2)
        elif A[h] > B[i]:
            e = h
            h = int((s+e)/2)
    for j in range(s, e):
        if A[j] == B[i]:
            A[j] = C[i]
    A.sort()
    print(sum(A))