import sys
# import math
input = sys.stdin.readline


def int_array():
    return list(map(int, input().strip().split()))


def str_array():
    return input().strip().split()

######################### TEMPLATE ENDS HERE ##################################

n = int(input())
arr = int_array()
b, c = [], []
n_c = int(input())
for i in range(n_c):
    tmp_b, tmp_c = int_array()
    b.append(tmp_b)
    c.append(tmp_c)

for i in range(n_c):
    for j in range(n):
        if arr[j] == b[i]:
            arr[j] = c[i]
    print(sum(arr))
    # print(arr)


