#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const double PI = atan(1.0) * 4;
const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};
const long long INF = (long long)2e18 + 50;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n;
  multiset<int> a;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    a.insert(b);
  }
  long long ans = 0;
  for (std::set<int>::iterator it = a.begin(); it != a.end(); ++it) {
    ans += *it;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int freq = a.count(b);
    ans -= freq * b;
    ans += freq * c;
    while (freq--) {
      a.erase(a.find(b));
      a.insert(c);
    }
    cout << ans << "\n";
  }
  return 0;
}
