#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
double getTime() { return clock() / (double)CLOCKS_PER_SEC; }
void read(){};
template <typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}
void print(){};
template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}
void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<int> cnt(100001, 0);
  for (auto& x : a) {
    cin >> x;
    cnt[x]++;
  }
  int q;
  cin >> q;
  ll sum = accumulate((a).begin(), (a).end(), 0);
  while (q--) {
    ll b, c;
    cin >> b >> c;
    sum -= b * cnt[b];
    sum += c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    print(sum);
  }
}
int main() {
  int t;
  t = 1;
  while (t--) solve();
}
