#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main(void) {
  int N;
  cin >> N;
  int t;
  vector<int> A(100000);
  int result = 0;
  for (int i = 0; i < N; i++) {
    cin >> t;
    A[t]++;
    result += t;
  }
  int Q;
  cin >> Q;
  int b, c;
  int temp;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    temp = A[b];
    A[b] = 0;
    A[c] += temp;
    result = result - b * temp + c * temp;
    cout << result << endl;
  }
  return 0;
}
