n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, c = list(map(int, input().split()))
    a_list.sort()
    index = []
    for i,j in enumerate(a_list):
        if j>b:
            break
        elif j==b:
            a_list[i]=c
    print(sum(a_list))