#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using vi = vector<int>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, sum = 0;
  cin >> N;
  vi a(N);
  map<int, int> mapa;
  for (auto& x : a) {
    cin >> x;
    sum += x;
    mapa[x]++;
  }
  vector<ll> r;
  int Q;
  cin >> Q;
  while (Q--) {
    int b, c;
    cin >> b >> c;
    sum -= (mapa[b] * b);
    sum += (mapa[b] * c);
    mapa[c] += mapa[b];
    mapa[b] = 0;
    r.push_back(sum);
  }
  for (auto& x : r) cout << x << endl;
  return 0;
}
