N = int(input())

target_list = map(int, input().split())
trans_list = {}

for i in range(int(input())):
    trans_list[i] = list(map(int, input().split()))

result = {}

for target in target_list:
    print(result)
    for key, trans in trans_list.items():
        if target == trans[0]:
            target = trans[1]

        if key in result:
            result[key] = result[key] + target
        else:
            result[key] = target


for r in result.values():
    print(r)
