import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)
N = ii()
A = [el for el in mips()]
Q = ii()
def ch(el,B,C):
    if el == B:
        return C
    return el
for i in range(Q):
    B,C = mips()
    A = [ch(el,B,C) for el in A]
    print(sum(A))