import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
na = np.array(a)
q = int(input())

for _ in range(q):
    cf, ca = map(int, input().split())
    na[na == cf] = ca
    print(na.sum())

