#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  int p[100005] = {0};
  int sum = 0, n, q, temp, a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    sum += temp;
    p[temp]++;
  }
  cin >> q;
  while (q--) {
    cin >> a >> b;
    sum = sum - a * p[a] + b * p[a];
    p[b] += p[a], p[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
