# -*- coding: utf-8 -*-
"""
Created on Sun Jun 21 23:57:41 2020

@author: Administrator
"""
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
while(Q):
    B,C=map(int,input().split())
    A.sort()
    lo = 0
    hi = N-1
    while(lo<hi):
        mid = lo + (hi-lo)//2
        if A[mid]>=B:
            hi = mid
        else:
            lo = mid + 1
    while(A[lo]==B):
        A[lo]=C
        lo += 1
    #print(A)
    print(sum(A))
    Q -= 1