package main

import (
	"fmt"
)

func main() {
	var n, q, b, c int64
	fmt.Scan(&n)
	a := make([]int64, n)
	an := int64(0)
	for i := int64(0); i < n; i++ {
		fmt.Scan(&an)
		a[i] = an
	}
	fmt.Scan(&q)
	for i := int64(0); i < q; i++ {
		fmt.Scan(&b, &c)
		for i, v := range a {
			if v == b {
				a[i] = c
			}
		}
		result := int64(0)
		for _, v := range a {
			result += v
		}
		fmt.Println(result)
	}
}
