import sys
input = sys.stdin.readline
 
n = int(input())
a = list(map(int, input().strip().split()))
q = int(input())
bc = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]
ii = 0
 
for i in b:
    for aa in a:
        if(aa==i):
            aa=c[i]
    i += 1
    print(sum(a))