#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for _ in range(Q)]


    for b, c in BC:
        A = [a if a != b else c for a in A]
        print(sum(A))


if __name__ == "__main__":
    main()
