import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
# q = int(input())
for i in range(int(input())):
    x,y = map(int, input().split())
    a = [y if b == x else b for b in a]
    print(sum(a))
