#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  set<int> s;
  map<int, int> m;
  set<int>::iterator itr;
  int p;
  for (int i = 0; i < n; i++) {
    cin >> p;
    s.insert(p);
    m[p]++;
  }
  int q;
  cin >> q;
  int ans;
  int pv;
  pv = 0;
  while (q--) {
    ans = 0;
    int b, c;
    cin >> b >> c;
    if (s.find(b) != s.end()) {
      s.erase(s.find(b));
      s.insert(c);
      m[c] += m[b];
      m[b] = 0;
      itr = s.begin();
      while (itr != s.end()) {
        ans += *itr * m[*itr];
        itr++;
      }
      cout << ans << endl;
    } else
      cout << pv << endl;
    pv = ans;
  }
}
