#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0, q;
  cin >> n;
  vector<int> a(n);
  unordered_map<int, int> um;
  for (int &i : a) {
    cin >> i;
    sum += i;
    um[i]++;
  }
  int b, c, um_b;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    um_b = um[b];
    um[c] += um_b;
    um[b] = 0;
    sum += (c * um_b) - (b * um_b);
    cout << sum << endl;
  }
  return 0;
}
