if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    q = int(input())
    key = [i for i in range(10**5+1)]
    val = [0]*(10**5+1)
    dict = dict(zip(key,val))
    dict.update(collections.Counter(a))
    ans = sum(a)

    for i in range(q):
        b, c = map(int, input().split())
        ans= ans - b*dict[b] + c*dict[b]
        count = dict[b]
        dict[b]=0
        dict[c]+=count
        print(ans)


