#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr int INF = 1 << 30;
constexpr long long LINF = 1LL << 60;
constexpr long long mod = 1e9 + 7;
constexpr int NIL = -1;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int n, q;
unordered_map<int, int> mp;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int ans = 0;
  for (int i = (1); i <= (n); i++) {
    int a;
    cin >> a;
    mp[a]++;
    ans += a;
  }
  cin >> q;
  for (int i = (1); i <= (q); i++) {
    int b, c;
    cin >> b >> c;
    mp[c] += mp[b];
    ans += -b * mp[b] + c * mp[b];
    mp[b] = 0;
    cout << ans << "\n";
  }
  return 0;
}
