#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& i : a) in >> i;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& a) {
  for (auto& i : a) out << i << " ";
  return out;
}
template <typename T, typename U>
void chkmin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void chkmax(T& a, U b) {
  if (a < b) a = b;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> cnt(1e5 + 2);
  for (int i = (int)0; i < (int)n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  long long s = 0;
  for (int i = (int)0; i < (int)n + 1; i++) s += 1LL * i * cnt[i];
  int q;
  cin >> q;
  while (q-- > 0) {
    int b, c;
    cin >> b >> c;
    s -= 1LL * b * cnt[b];
    s += 1LL * c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << s << "\n";
  }
  return 0;
}
