#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> mp;
  long long sum = 0;
  for (auto &x : v) {
    cin >> x;
    sum += x;
    mp[x]++;
  }
  int q, b, c;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    if (mp[b]) {
      sum -= b * mp[b];
      sum += c * mp[b];
      mp[c] += mp[b];
      mp[b] = 0;
    }
    cout << sum << '\n';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
