#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A.at(i);
  ll Q;
  cin >> Q;
  vector<ll> B(Q), C(Q);
  for (int i = 0; i < (int)(Q); i++) {
    cin >> B.at(i) >> C.at(i);
  }
  int MAX = 100000;
  vector<long> S(Q);
  vector<int> count(MAX, 0);
  for (int i = 0; i < (int)(N); i++) {
    count.at(A.at(i))++;
  }
  long sum = 0;
  for (int i = 0; i < (int)(N); i++) {
    sum += A.at(i);
  }
  for (int i = 0; i < (int)(Q); i++) {
    int num = count.at(B.at(i));
    int diff = C.at(i) - B.at(i);
    count.at(B.at(i)) = 0;
    count.at(C.at(i)) += num;
    sum += diff * num;
    S.at(i) = sum;
  }
  for (int i = 0; i < (int)(Q); i++) {
    cout << S.at(i) << endl;
  }
}
