#include <bits/stdc++.h>
using namespace std;
int solve() {
  int n;
  cin >> n;
  vector<int> v(100001, 0);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    int ii;
    cin >> ii;
    v[ii]++;
    sum += ii;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int long long, mm;
    cin >> long long >> mm;
    sum -= v[long long] * long long;
    sum += v[long long] * mm;
    v[mm] = v[mm] + v[long long];
    v[long long] = 0;
    cout << sum << "\n";
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
