import sys
from collections import deque
import numpy as np
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = np.array(list(IL()),dtype='int64')
    q = I()
    s = deque()
    for rep in range(q):
        b,c = IL()
        a[a==b] = c
        s.append(sum(a))
    for _ in range(q):
        print(s.popleft())
    return

if __name__=='__main__':
    Main()