n = int(input())
a = list(map(int,input().split()))
q = int(input())
count = 0
v = []
for i in range(q):
    b,c = list(map(int,input().split()))
    if a.count(b) != 0:
        count = 0
        v = []
        for j in range(n):
            if a[j] == b:
                v.append(c)
            else:
                v.append(a[j])
            count += v[j]
    print(count)
    a = v