#!/usr/bin/env python3
def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    Q = int(input())

    sum_A = sum(A)
    for _ in range(Q):
        B, C = map(int, input().split())

        sum_A = sum_A + A.count(B) * (C - B)
        print(sum_A)
        A = [C if x == B else x for x in A]


if __name__ == '__main__':
    main()
