#!/usr/bin/env python3
import sys
import numpy as np
sys.setrecursionlimit(1000000000)


def main():
    input()
    A = np.fromstring(input(), 'int', sep=' ')
    Q = int(input())
    for i in range(Q):
        B, C = map(int, input().split())
        A = np.where(A == B, C, A)
        print(np.sum(A))


if __name__ == "__main__":
    main()
