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

N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())

for line in readlines():
    B, C = map(int, line.split())

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