package main
import(
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc=bufio.NewScanner(os.Stdin)
var wtr=bufio.NewWriter(os.Stdout)
func nextInt() int{
  sc.Scan()
  i, e :=strconv.Atoi(sc.Text())
  if e!=nil{
    panic(e)
  }
  return i
}
func main(){
  var i, j, n, q int
  sc.Split(bufio.ScanWords)
  n=nextInt()
  a:=make([]int, n)
  for i=0;i<n;i++{
    a[i]=nextInt()
  }
  q=nextInt()
  b:=make([]int, q)
  c:=make([]int, q)
  ans:=make([]int64, q)
  for j=0;j<q;j++{
    b[j]=nextInt()
    c[j]=nextInt()
  }
  for j=0;j<q;j++{
  	for i=0;i<n;i++{
       if b[j]==a[i]{
         a[i]=c[j]
    	}
    	ans[j]+=int64(a[i])
  	}
 	fmt.Fprintln(wtr,ans[j])
   _ = wtr.Flush()
  }
}
