#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n, 0);
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long sum = 0;
  sum = accumulate(a.begin(), a.end(), 0LL);
  long long q;
  cin >> q;
  vector<long long> b(n, 0), c(n, 0);
  for (long long i = 0; i < q; i++) cin >> b[i] >> c[i];
  vector<long long> dp(1000000, 0);
  for (long long i = 0; i < n; i++) {
    dp[a[i]] += 1;
  }
  long long ans = sum;
  for (long long i = 0; i < q; i++) {
    ans = ans - (b[i] * dp[b[i]]) + (c[i] * dp[b[i]]);
    dp[c[i]] = dp[c[i]] + dp[b[i]];
    dp[b[i]] = 0;
    cout << ans << endl;
  }
  return 0;
}
