#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
constexpr ll atcoder_mod = 1e9 + 7;
template <typename T = ll>
T in() {
  T x;
  cin >> x;
  return (x);
}
template <typename T = ll, typename C = vector<T>>
C vecin(int N) {
  C x(N);
  for (ll i = 0; i < (N); ++i) {
    x[i] = in<T>();
  }
  return x;
}
void vout() { cout << endl; }
template <typename Head, typename... Tail>
void vout(Head&& h, Tail&&... t) {
  cout << ' ' << h;
  vout(forward<Tail>(t)...);
}
void out() { cout << endl; }
template <typename Head, typename... Tail>
void out(Head&& h, Tail&&... t) {
  cout << h;
  vout(forward<Tail>(t)...);
}
template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll N = in();
  auto A = vecin(N);
  map<ll, ll> M;
  for (auto& x : A) M[x]++;
  ll S = accumulate(A.begin(), A.end(), 0);
  ll Q = in();
  while (Q--) {
    ll B = in(), D = in();
    ll X = M[B];
    S += -B * X + X * D;
    M[D] += M[B];
    M[B] = 0;
    out(S);
  }
  return 0;
}
