#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline constexpr ll Inf = (1ULL << 62) - 1;
template <class T>
void updatemax(T& a, T b) {
  if (b > a) a = b;
}
int main() {
  ll N;
  cin >> N;
  vector<int> s(1e5 + 1);
  int sum = 0;
  for (decltype(N) i = 0; i < N; ++i) {
    int a;
    cin >> a;
    sum += a;
    s[a]++;
  }
  int q;
  cin >> q;
  for (decltype(q) i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    sum += s[b] * (c - b);
    s[c] += s[b];
    s[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
