#!/usr/bin/env python3
import sys
n = int(input())
p = list(map(int,input().split()))
q = int(input())

xy = [map(int,input().split()) for _ in range(q)]
x, y = [list(i) for i in zip(*xy)]

for i in range(q):
    for j in range(len(p)):
        if p[j] == x[i]:
            p[j] = y[i]
    print(sum(p))