#!/usr/bin/env python3
import sys
import numpy as np
import numba
sys.setrecursionlimit(1000000000)
MOD = 10 ** 9 + 7


@numba.jit('void (i4[:], i4[:,:])', nopython=True)
def calc(A, BC):
    for i in range(len(BC)):
        A = np.where(A == BC[i][0], BC[i][1], A)
        print(np.sum(A))


def main():
    input()
    A = np.fromstring(input(), 'int', sep=' ')
    Q = int(input())
    BC = np.array([list(map(int, input().split())) for _ in range(Q)])
    calc(A, BC)


if __name__ == "__main__":
    main()
