import collections
input()
math_dic = collections.Counter((map(int,input().split())))
num = int(input())
for i in range(num):
    a,b = map(int,input().split())
    if a not in math_dic:
        print(sum([index*value for index,value in math_dic.items()]))
        continue
    if b not in math_dic:
        math_dic[b] = 0
    math_dic[b] += math_dic.pop(a)
    print(sum([index*value for index,value in math_dic.items()]))