package main

import "fmt"
import "bufio"
import "os"
import "strconv"

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func twoInt() (int, int) {
	var a, b int
	fmt.Scan(&a, &b)
	return a, b
}

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

	A := make([]int, N)
	sc.Split(bufio.ScanWords)

	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}

	var Q int
	fmt.Scan(&Q)

	B := make([]int, Q)
	C := make([]int, Q)

	S := make([]int64, Q)

	for i := 0; i < Q; i++ {
		B[i], C[i] = twoInt()
	}

	var tmpB, tmpC int
	var tmpS int64
	for i := 0; i < Q; i++ {
		tmpB = B[i]
		tmpC = C[i]
		for j := 0; j < N; j++ {
			if A[j] == tmpB {
				A[j] = tmpC
			}
		}

		tmpS = 0
		for k := 0; k < N; k++ {
			tmpS = tmpS + int64(A[k])
		}

		S[i] = tmpS

	}

	for i := 0; i < Q; i++ {
		fmt.Println(S[i])
	}

}
