function main(input) {
  let args = input.split('\n');
  // let item = args[a++].split(' ').map((e) => +e);
  let a = 0;
  let n = +args[a++];
  let sum = 0;
  let map = {};
  let arr = args[a++].split(' ').map((e) => +e);
  for (let i = 0; i < n; ++i) {
    let x = arr[i];
    sum += x;
    if (map[x] != null) {
      map[x]++;
    } else {
      map[x] = 1;
    }
  }

  let q = +args[a++];
  for (let i = 0; i < q; ++i) {
    let [b, c] = args[a++].split(' ').map((e) => +e);
    if (map[b] && map[b] > 0) {
      let ct = map[b];
      sum -= ct * b;
      map[b] = 0;
      if (map[c]) {
        map[c] += ct;
      } else {
        map[c] = ct;
      }
      sum += ct * c;
    }
    console.log(sum);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
