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