# coding: utf-8
n = int(input())

list_a = map(int, input().split())

q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    list_a = list(map(lambda a: c if a==b else a, list_a))
    print(sum(list_a))
