def solve():
    n=int(input())
    r=range
    a=list(map(int, input().split()))
    q=int(input())
    
    for _ in r(q):
        bi, ci = map(int, input().split())
        c=0
        for i in r(n):
            if a[i] == bi:
                a[i]=ci
            c+=a[i]
        print(c)


if __name__ == '__main__':
    t=1
    for _ in range(t):
        solve()
