def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())
    import numpy as np
    A.sort()
    ans = sum(A)
    for i in range(q):
        b,c = map(int, input().split())
        count = 0
        for j,a in enumerate(A):
            if a == b:
                A[j]=c
                count += 1
            elif a > b:
                break
        ans += (c-b)* count
        print(ans)

if __name__ == '__main__':
    main()