#include <bits/stdc++.h>
using namespace std;
void solve() {
  map<int, int> all;
  int n, q;
  long long int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    all[temp]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int origin, replace;
    cin >> origin >> replace;
    if (all[origin] == 0) {
      cout << sum << endl;
      continue;
    } else {
      sum -= origin * all[origin];
      sum += replace * all[origin];
      all[replace] += all[origin];
      all[origin] = 0;
      cout << sum << endl;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
