n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    ans = 0
    x,y = map(int,input().split())
    for j in range(n):
        if a[j] == x:
            a[j] = y
        ans += a[j]
    print(ans)