from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    q = int(input())
    bc = [map(int, input().split()) for _ in range(q)]
    temp = suma(a)
    for b,c in bc:
        t = a[b]
        temp -= b*t
        a[c] += t
        temp += c*t
        print(temp)

def suma(a):
    x = 0
    for i in a.items():
        x += i[0] * i[1]
    return x

if __name__ == '__main__':
    main()