import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');

_d(input);

function _d(input: string) {
  const [_n, _a, _q, ..._bc] = input.split('\n');
  _bc.splice(-1, 1); // 末尾の改行を取り除く

  const A = _a.split(' ').map(Number);
  const BC = _bc.map((b_c) => {
    const [b, c] = b_c.split(' ');
    return [parseInt(b), parseInt(c)] as const;
  });

  for (const [B, C] of BC) {
    let sum = 0n;
    for (let i = 0; i < A.length; i++) {
      if (A[i] === B) {
        A[i] = C;
      }
      sum += BigInt(A[i]);
    }
    console.log(sum.toString());
  }
}
