n = int(input())
a = list(map(int, input().split()))

q = int(input())
b = []
c = []

for i in range(q):
    B, C = [int(i) for i in input().split()]
    b.append(B)
    c.append(C)

int_list = {}

for i in a:
    int_list[i] = 0

for i in a:
    int_list[i] += 1

ans = 0
for k, v in int_list.items():
    ans += k*v # 3


for i in range(q):
    ans = 0
    p = int_list[b[i]] # 1 1
    ans = 0
    int_list[b[i]] = 0
    try:
        int_list[c[i]] += p
    except KeyError:
        int_list[c[i]] = p
    for k, v in int_list.items():
        ans += k*v
    
    print(ans)