n=int(input())
a=list(map(int,input().split()))
x=sum(a)
u,v=[],[]
for i in a:
    if not i in u:
        u+=[i]
        v+=[1]
    else:
        v[u.index(i)]+=1
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    for j in range(len(u)):
        if u[j] == b:
            u[j]=c
            x+=v[j]*(c-b)
    print(x)