#include <bits/stdc++.h>
using namespace std;
map<int, int> Map;
int main() {
  int n, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    sum += t;
    Map[t]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t, k, c;
    cin >> t >> k;
    c = Map[t];
    sum += (k - t) * c;
    Map[t] = 0;
    Map[k] += c;
    cout << sum << endl;
  }
}
