#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
int in() {
  int a;
  cin >> a;
  return a;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  long long int sum = 0;
  map<int, int> m;
  for (int& it : a) {
    cin >> it;
    sum += it;
    m[it]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= m[b] * b;
    sum += m[b] * c;
    cout << sum << endl;
    m[c] += m[b];
    m[b] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(0);
  cerr.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
