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

aa = set()

for i in range(q):
    b,c = map(int,input().split())
    if b not in aa:
        aa.add(b)
        l = [c if j == b else j for j in l ]
    print(sum(l))