def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for _ in range(Q)]

    a_dict = {}
    for i in A:
        if i in a_dict:
            a_dict[i] += 1
        else:
            a_dict[i] = 1

    for b, c in BC:
        if b in a_dict:
            if c in a_dict:
                a_dict[c] += a_dict.pop(b)
            else:
                a_dict[c] = a_dict.pop(b)
        print(sum([k * v for k, v in a_dict.items()]))

if __name__ == "__main__":
    resolve()