package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	n, _ := sc.NextInt()
	a, _ := sc.NextInts(n)
	q, _ := sc.NextInt()
	b, c := make([]int, q), make([]int, q)
	for i := 0; i < q; i++ {
		b[i], _ = sc.NextInt()
		c[i], _ = sc.NextInt()
	}
	ans := solve(n, q, a, b, c)
	for _, v := range ans {
		fmt.Println(v)
	}
}

func solve(n, q int, a, b, c []int) (ans []int) {
	count := map[int]int{}
	for _, v := range a {
		count[v]++
	}
	ans = make([]int, q)
	for i := 0; i < q; i++ {
		count[c[i]] += count[b[i]]
		delete(count, b[i])
		ans[i] = sum(count)
	}
	return ans
}

func sum(count map[int]int) int {
	ret := 0
	for k, v := range count {
		ret += k * v
	}
	return ret
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}

// NextInts reads n integers from io stream.
func (sc *Scanner) NextInts(n int) (arr []int, e error) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		v, e := sc.NextInt()
		if e != nil {
			return nil, e
		}
		arr[i] = v
	}
	return arr, nil
}
