#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
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() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> cnt(100005, 0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll sum = 0;
  for (int i = 0; i < 100005; i++) {
    sum += cnt[i] * i;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int c, d;
    cin >> c >> d;
    sum -= cnt[c] * c;
    sum += cnt[c] * d;
    cnt[d] += cnt[c];
    cnt[c] = 0;
    cout << sum << "\n";
  }
  return 0;
}
