#include <bits/stdc++.h>
using namespace std;
int main() {
  long N, Q;
  vector<long> index(100001, 0);
  cin >> N;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    index[tmp]++;
  }
  cin >> Q;
  vector<vector<long>> B(Q, vector<long>(2, 0));
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i).at(0) >> B.at(i).at(1);
  }
  long sum = 0;
  for (int i = 0; i < 100001; i++) {
    sum += i * index[i];
  }
  for (int i = 0; i < Q; i++) {
    long tmp1, tmp2;
    tmp1 = B.at(i).at(0);
    tmp2 = B.at(i).at(1);
    sum += (tmp2 - tmp1) * index[tmp1];
    index[tmp1] = 0;
    index[tmp2] += index[tmp1];
    cout << sum << endl;
  }
}
