#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  int n, input;
  cin >> n;
  vector<int> a(10001, 0);
  for (int i = 0; i < n; ++i) {
    cin >> input;
    a[input]++;
  }
  ll ans = 0;
  for (int i = 0; i <= 10001; ++i) {
    ans += a[i] * i;
  }
  int q, b, c;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> b >> c;
    ans += (c - b) * a[b];
    cout << ans << "\n";
    a[c] += a[b];
    a[b] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
