#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
  os << '(' << a.first << ',' << a.second << ')';
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto x : v) os << x << ' ';
  return os;
}
void debug() { cerr << '\n'; }
template <typename H, typename... T>
void debug(H a, T... b) {
  cerr << a;
  if (sizeof...(b)) cerr << ", ";
  debug(b...);
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); ++i) cin >> a[i];
  ll sum = 0;
  map<int, int> mp;
  for (int i = 0; i < (int)(n); ++i) mp[a[i]]++;
  for (int i = 0; i < (int)(n); ++i) sum += a[i];
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    ll k = mp[b] * b;
    sum -= k;
    mp[c] += mp[b];
    sum += c * mp[b];
    mp[b] = 0;
    cout << sum << "\n";
  }
}
