package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	a := make([]int, n)
	for i := 0; i < len(a); i++ {
		fmt.Scanf("%d", &a[i])
	}

	var q int
	fmt.Scanf("%d", &q)

	b := make([][]int, q)
	for i := 0; i < len(b); i++ {
		b[i] = make([]int, 2)
		fmt.Scanf("%d", &b[i][0])
		fmt.Scanf("%d", &b[i][1])
	}

	for i := 0; i < len(b); i++ {
		ans := 0
		for j := 0; j < len(a); j++ {
			if b[i][0] == a[j] {
				a[j] = b[i][1]
			}
			ans = ans + a[j]
		}

		fmt.Println(ans)
	}
}
