#!/usr/bin/env python3

def main():
    N = int(input())
    a = [0] + list(map(int,input().split()))
    d = [0] + [a.count(i+1) for i in range(10**5)]
    Q = int(input())
    s = sum(a)
    for _ in range(Q):
        B,C = map(int,input().split())
        if d[B] != 0:
            tmp = d[B]
            d[B] = 0
            d[C] += tmp
            s = s - tmp*B + tmp*C
        print(s)




if __name__ == '__main__':
    main()
