import sys
import bisect
input = sys.stdin.readline

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

for i in range(q):
    b,c = map(int, input().split())
    if b in a:
        left = bisect.bisect_left(a,b)
        right = bisect.bisect_right(a,b)
        if left == right:
            right += 1
        a[left:right] = [c for i in range(right-left)]
    print(sum(a))
    a.sort()