n = int(input())
lst = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    a, b = map(int, input().split())
    summ = 0
    for i in range(n):
        if lst[i] == a:
            lst[i] = b
            summ += lst[i]
        else:
            summ += lst[i]
    print(summ)