#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long A;
  vector<long long> vec;
  vec.reserve(10001);
  for (auto i = 0; i < 10001; i++) {
    vec.push_back(0);
  }
  long long ret = 0;
  for (auto i = 0; i < N; i++) {
    cin >> A;
    vec[A]++;
    ret += A;
  }
  long long Q, B, C;
  cin >> Q;
  for (auto i = 0; i < Q; i++) {
    cin >> B >> C;
    ret += (C - B) * vec[B];
    vec[C] += vec[B];
    vec[B] = 0;
    cout << ret << endl;
  }
  return 0;
}
