import sys
from collections import Counter

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


def print_sum(d):
    s = 0
    for k, v in d.items():
        s += k * v
    print(s)


n = I()
al = list(MI())
q = I()

a = Counter(al)

for i in range(q):
    b, c = MI()
    if b in a.keys():
        v = a.pop(b)
        if c in a.keys():
            a[c] += v
        else:
            a[c] = v

    print_sum(a)
