#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long> > que;
priority_queue<long long> Que;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
void solve() {
  int n, q;
  cin >> n;
  long long a;
  long long dp[100005];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) {
    cin >> a;
    dp[a]++;
  }
  cin >> q;
  long long b, c;
  long long ans = 0;
  long long k = 0;
  for (long long x : dp) {
    ans += (x * k);
    k++;
  }
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    long long t = dp[b];
    ans -= (b * t);
    dp[c] += t;
    ans += (t * c);
    cout << ans << endl;
  }
}
int main() {
  solve();
  return 0;
}
