#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> x;
  ll sum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    x[a[i]]++;
    sum += a[i];
  }
  int q;
  vector<P> bc(q);
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    bc[i].first = b;
    bc[i].second = c;
  }
  for (int i = 0; i < (q); ++i) {
    ll y = bc[i].second - bc[i].first;
    sum += y * x[bc[i].first];
    cout << sum << endl;
    x[bc[i].second] += x[bc[i].first];
    x[bc[i].first] = 0;
  }
  return 0;
}
