#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, q, b, c, sum = 0, ans;
  long long dp[100001] = {0};
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    dp[a[i]]++;
  }
  cin >> q;
  while (q--) {
    ans = 0;
    cin >> b >> c;
    if (dp[b]) {
      ans += dp[b] * c;
      sum -= dp[b] * b;
      dp[c] += dp[b];
      ans += sum;
      sum = ans;
      cout << ans << "\n";
    } else
      cout << sum << "\n";
  }
  return 0;
}
