import bisect

def func2(l, value):
    i = -1
    c = len(l)
    result = []
    while i < c:
        try:
            i = l.index(value, i + 1)
            result.append(i)
        except:
            return result
    return result

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

for i in range(q):
    b,c = map(int,input().split())
    if a_li not in b:
        print(sum(a_li))
        continue
    indexes = func2(a_li, b)
    for i in indexes:
        a_li[i] = c
    print(sum(a_li))