def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B = []
    C = []
    a = sum(A)
    for _ in range(Q):
        b, c = map(int, input().split())
        a += (A.count(b))*(c-b)
        print(a)
        B.append(A.count(b))
        C.append(c)

if __name__ == '__main__':
    main()