N = int(input())
li = list(map(int,input().split()))
Q = int(input())
import bisect
for i in range(Q):
    b,c = map(int,input().split())
    li.sort()
    ind = bisect.bisect_left(li,b)
    if ind>N-1:
        print(sum(li))
    elif li[ind]==b:
        while li[ind]==b:
          li[ind]=c
          if ind!=N-1:
              ind+=1
          else:
            break
        print(sum(li))