#include <bits/stdc++.h>
using namespace std;
int n, t[100005], fv[100005], i, j, k, a, b, sum;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> t[i], fv[t[i]]++, sum += t[i];
  cin >> k;
  while (k--) {
    cin >> a >> b;
    sum -= a * fv[a];
    sum += b * fv[a];
    fv[b] += fv[a];
    fv[a] = 0;
    cout << sum << endl;
  }
}
