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