#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vv = vector<vector<T>>;
using vi = vector<long long>;
using vvi = vector<vector<long long>>;
using P = pair<long long, long long>;
using ll = long long;
constexpr ll INF = 1LL << 60;
signed main() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  map<long long, bool> con;
  vector<long long> a(n);
  long long sum = 0;
  for (long long i = 0; i < (n); ++i) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < (q); ++i) {
    long long b, c;
    cin >> b >> c;
    sum -= b * mp[b];
    sum -= c * mp[c];
    mp[c] += mp[b];
    sum += c * mp[c];
    cout << sum << endl;
  }
  return 0;
}
