#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
const int MOD = 1000000007;
void solve() {
  int n;
  cin >> n;
  map<long long, long long> mp;
  long long res = 0;
  for (int i = 0; i < (n); ++i) {
    long long a;
    cin >> a;
    mp[a]++;
    res += a;
  }
  int q;
  cin >> q;
  vector<long long> b(q);
  vector<long long> c(q);
  for (int i = 0; i < (q); ++i) cin >> b[i] >> c[i];
  for (int i = 0; i < (q); ++i) {
    if (!mp[b[i]])
      continue;
    else {
      res -= b[i] * mp[b[i]];
      res += c[i] * mp[b[i]];
      mp[c[i]] += mp[b[i]];
      mp[b[i]] = 0;
      cout << res << endl;
    }
  }
}
int main() {
  solve();
  return 0;
}
