#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-06-21 21:56:58 +0900
# LastModified: 2020-06-21 22:06:42 +0900
#


import copy

def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    for _ in range(q):
        b,c = map(int, input().split())
        a = [i if i != b else c for i in a]
        print(sum(a))


if __name__ == "__main__":
    main()
