#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0;
  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--) {
    int b, c;
    cin >> b >> c;
    if (temp.find((int)b) != temp.end()) {
      sum = sum - b * temp[b];
      sum = sum + c * temp[b];
      temp[c] = temp[c] + temp[b];
      temp[b] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}
