#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  long long sum = 0;
  int a;
  unordered_map<int, int> f;
  for (int i = 0; i < n; i++) {
    cin >> a;
    f[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  int b, c;
  while (q--) {
    cin >> b >> c;
    sum -= b * f[b];
    sum += c * f[b];
    f[c] += f[b];
    f.erase(b);
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
