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