def resolve():
    n=int(input())
    a = list(map(int, input().split()))
    ans=sum(a)
    q=int(input())
    a_dict = {}
    for i in set(a):
        a_dict[str(i)] = 0
    for j in a:
        a_dict[str(j)] += 1
    ch=list(a_dict.keys())
    for _ in range(q):
        b,c = map(str, input().split())
        if b in ch:
            d = a_dict[b]
            a_dict[b]=0
            if c in ch:
                a_dict[c] += d
            else:
                a_dict[c] = d
                ch.append(c)
            ans=ans-d*(int(b)-int(c))
            print(ans)
        else:
            print(ans)
resolve()