#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  vector<ll> A(n), C(n + 10);
  ll sum = 0;
  for (int i = 0; i < (n); i++) {
    cin >> A[i];
    C[A[i]]++;
    sum += A[i];
  }
  int q;
  cin >> q;
  vector<ll> res;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * C[b];
    res.push_back(sum);
    C[c] += C[b];
    C[b] = 0;
  }
  for (auto num : res) cout << num << ln;
}
