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])
	}

	ans := make([]int, q)
	for i := 0; i < len(a); i++ {
		_ans := a[i]

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

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