#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long int n, q, i, j, b, c, l;
  cin >> n;
  long long int s = 0, ans;
  long int a[n], dp[100002] = {0};
  for (i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]]++;
    s += a[i];
  }
  cin >> q;
  l = q;
  ans = s;
  while (q--) {
    cin >> b >> c;
    if (dp[b]) {
      ans += c * dp[c] - b * dp[b];
      dp[c] += dp[b];
      dp[b] = 0;
    }
    cout << ans << endl;
  }
}
