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)]
 
for i in range(q):
    for aa in range(n):
        if(a[aa]==b[i]):
            a[aa]=c[i]
    print(sum(a))