
n = int(input())
x = list(map(int,input().split()))

for i in range(int(input())):
    q , c = map(int,input().split())
    
    for i in range(x.count(q)):
        x[x.index(q)] = c
    print(sum(x))