#include <bits/stdc++.h>
using namespace std;
void YN(bool flg) {
  if (flg)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void Yn(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void yn(bool flg) {
  if (flg)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}
int main() {
  int n;
  cin >> n;
  int sum = 0;
  map<int, int> m;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    m[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    if (m.find(b) != m.end()) {
      int cnt = m[b];
      sum -= (b * cnt);
      sum += (c * cnt);
      m.erase(b);
      m[c] += cnt;
    }
    cout << sum << endl;
  }
  return 0;
}
