#include <bits/stdc++.h>
using namespace std;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args>
void my_dbg(Arg A, Args... B) {
  cout << ' ' << A;
  my_dbg(B...);
}
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int N = 2e5 + 2;
void solve() {
  int n;
  scanf("%d", &n);
  map<int, int> ma;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int val;
    scanf("%d", &val);
    sum += 1LL * val;
    ma[val]++;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d", &b);
    scanf("%d", &c);
    if (ma.count(b)) {
      sum -= (ma[b] * b);
      sum += (ma[b] * c);
      ma[c] += ma[b];
      ma.erase(b);
    }
    printf("%lld\n", sum);
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
