def sousa(target_list, before, after):
    sum = 0
    for i in range(len(target_list)):
        if target_list[i] == before:
            target_list[i] = after
        sum += target_list[i]
    return target_list, sum


def main():
    _ = input()
    target_list = list(map(int, input().split()))
    sousa_list = list()
    for i in range(int(input())):
        sousa_list.append(list(map(int, input().split())))

    for i in range(len(sousa_list)):
        target_list, summary = sousa(target_list, sousa_list[i][0], sousa_list[i][1])
        print(summary)


if __name__ == '__main__':
    main()
