n = int(input())

a = list(map(int, input().split()))

q = int(input())

for i in range(q):
    
    b,c = map(int, input().split())
    
    if b in a:
        index = [i for i, x in enumerate(a) if x == b]
        
        if len(index) == n:
            a = [c] * n
        else:  
            for i in index:
                a[i] = c

    print(sum(a))