#                               #
    # author : samars_diary #
    # 18-09-2020 │ 15:37:26 #
#                               #

import sys, os.path

if(os.path.exists('input.txt')):
    sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    a=ii();b=lii();c=ii();s=sum(b)
    for _ in range(c):
        d,e=mii() ; f=b.count(d)
        for _ in range(f): b.remove(d);b.append(e)
        s-=f*d-f*e
        print(s)
for _ in range(1): solve()