#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<int> A(100000);
  ll sum = 0;
  for (int i = 0; i < (N); ++i) {
    int tmp;
    cin >> tmp;
    A.at(tmp)++;
    sum += tmp;
  }
  int Q;
  cin >> Q;
  vector<vector<int>> bc(Q, vector<int>(2));
  for (int i = 0; i < (Q); ++i) {
    cin >> bc.at(i).at(0) >> bc.at(i).at(1);
  }
  for (int i = 0; i < (Q); ++i) {
    sum += (bc.at(i).at(1) - bc.at(i).at(0)) * A.at(bc.at(i).at(0));
    cout << sum << endl;
    A.at(bc.at(i).at(1)) += A.at(bc.at(i).at(0));
    A.at(bc.at(i).at(0)) = 0;
  }
}
