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