#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> mp;
  long long prefix = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    ++mp[v[i]];
    prefix += v[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    mp[c] += mp[b];
    prefix -= b * mp[b];
    prefix += c * mp[b];
    mp[b] = 0;
    cout << prefix << '\n';
  }
  return 0;
}
