#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long double PI = 3.14159265358979323846;
using ll = long long;
const ll modo = 1e9 + 7;
const ll inf = LONG_LONG_MAX;
const ll ms = (2e5) + 5;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n;
  cin >> n;
  map<int, int> mm;
  int i, j, e;
  ll ans = 0;
  for (i = 1; i <= n; i++) {
    cin >> e;
    mm[e]++;
    ans += e;
  }
  int q;
  cin >> q;
  int a, b;
  while (q--) {
    cin >> a >> b;
    e = mm[a];
    ans = (ans - (e * a));
    ans = (ans + (e * b));
    if (e) {
      mm.erase(a);
      mm[b] += e;
    }
    cout << ans << "\n";
  }
  return 0;
}
