#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ai, bi, ci, sum = 0, q;
  int arra[100002];
  memset(arra, 0, sizeof(arra));
  cin >> n;
  while (n--) {
    cin >> ai;
    arra[ai]++;
    sum += ai;
  }
  cin >> q;
  while (q--) {
    cin >> bi >> ci;
    sum = sum - (bi * arra[bi]) + (ci * arra[bi]);
    arra[ci] += arra[bi];
    arra[bi] = 0;
    cout << sum << '\n';
  }
  return 0;
}
