#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long i, j, n, k;
  cin >> n;
  long long a[n], sum = 0;
  long long hash[100008] = {};
  for (i = 0; i < n; ++i) {
    cin >> a[i];
    hash[a[i]]++;
    sum += a[i];
  }
  cin >> k;
  while (k--) {
    cin >> i >> j;
    if (hash[i]) {
      long long cnt = hash[i];
      hash[j] = hash[i];
      hash[i] = 0;
      sum += cnt * (j - i);
      cout << sum << "\n";
    } else {
      cout << sum << "\n";
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  long long _t = 1;
  while (_t--) solve();
}
