# -*- coding: utf-8 -*-
import collections

N = int(input())
A = 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)]


def replace_list(num_list):
    num_list = [y[index] if j==i else j for j in num_list]
    return num_list




for index, i in enumerate(x):
    #first_sum = sum(A)
    #c = collections.Counter(A)
    #first_sum = c[i]*(y[index]-i)+first_sum
    while i in A :
        A.remove(i)  #全てのiを削除します。
        A.append(y[index])
    first_sum = sum(A)
    print(first_sum)
    
