#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
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;
}
const double PI = 3.1415926535897932;
int n;
int q;
int a[100005];
multiset<int> s;
int cnt[100008];
lint ans = 0;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < int(n); i++) {
    cin >> a[i];
    cnt[a[i]]++;
    ans += a[i];
  }
  cin >> q;
  for (int i = 0; i < int(q); i++) {
    int b, c;
    cin >> b >> c;
    cnt[c] += cnt[b];
    ans += lint(cnt[b] * c);
    ans -= lint(cnt[b] * b);
    cnt[b] = 0;
    cout << ans << endl;
  }
  return 0;
}
