n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = []

for i in range(q):
    b, c = map(int, input().split())
    d = []
    for j in a:
        if j == b:
            d.append(c)
        else:
            d.append(j)
    print(sum(d))
    a = d