package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	var sum uint64
	for i:= 0; i < n; i++ {
		fmt.Scan(&a[i])
		sum += uint64(a[i])
	}

	sort.Ints(a)

	var q int
	fmt.Scan(&q)

	b := make([]int , q)
	c := make([]int , q)
	for i:= 0; i < q; i++ {
		fmt.Scan(&b[i], &c[i])
	}
	for i := 0; i < q; i++ {
		for j := 0; j < n; j++ {
			if a[j] == b[i] {
				a[j] = c[i]
				sum -= uint64((b[i]-c[i]))
				//break
			} else if b[i] < a[j] {
				break
			}
		}
		sort.Ints(a)
		fmt.Println(sum)
	}
	// fmt.Println(a)
}

