def readInt():
    return list(map(int, input().split()))
    
n = int(input())
a = readInt()
q = int(input())
for i in range(q):
    b,c = readInt()
    # print(b,c)
    a_c = []
    for i in a:
        if i==b:
            a_c.append(c)
        else:
            a_c.append(i)
    print(sum(a_c))
    a = a_c