#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vvp = vector<vector<pair<int, int>>>;
template <typename T>
using ve = vector<T>;
template <typename T>
using pq2 = priority_queue<T>;
template <typename T>
using pq1 = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vl A(N);
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
  };
  ll sum = 0;
  map<ll, ll> A_map;
  for (int i = 0; i < (N); i++) sum += A[i];
  for (int i = 0; i < (N); i++) A_map[A[i]]++;
  int Q;
  cin >> Q;
  vl ans;
  for (int qqq = 0; qqq < (Q); qqq++) {
    ll B, C;
    cin >> B >> C;
    ll a = A_map[B];
    sum -= B * a;
    A_map[C] += a;
    sum += C * a;
    ans.push_back(sum);
  }
  for (int i = 0; i < (Q); i++) cout << ans[i] << endl;
  return 0;
}
