#!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline

N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())
answer = [0] * Q

for i in range(Q):
    B, C = map(int, readline().split())

    A = [(C if num == B else num) for num in A]
    answer[i] = sum(A)

print(*answer, sep='\n')
