#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 (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
    sum += v[i];
  }
  int q;
  cin >> q;
  vector<pair<int, int>> vq(q);
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    vq[i] = {a, b};
  }
  for (auto i : vq) {
    sum = sum - mp[i.first] * i.first + mp[i.first] * i.second;
    mp[i.second] += mp[i.first];
    mp[i.first] = 0;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
