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