import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    bc = []
    for _ in range(q):
        bc.append(list(map(int, input().split())))

    for element in bc:
        for i in range(len(a)):
            if a[i] == element[0]:
                a[i] = element[1]
        print(sum(a))


if __name__ == '__main__':
    main()
