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