#include <bits/stdc++.h>
using namespace std;
const long long MAX_NUM = 1000000000000001;
int main() {
  int N;
  cin >> N;
  long long ans = 0;
  vector<int> A(100001, 0);
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    ans += tmp;
    A.at(tmp)++;
  }
  int Q;
  cin >> Q;
  vector<long long> sum(Q);
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    int tmp = A.at(b);
    A.at(c) += tmp;
    A.at(b) = 0;
    ans -= b * tmp;
    ans += c * tmp;
    sum.at(i) = ans;
  }
  for (int i = 0; i < Q; i++) cout << sum.at(i) << endl;
  return 0;
}
