#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD_NUM = 1e9 + 7;
ll sum_by_a_count(const vector<int>& a_count) {
  ll ans = 0;
  for (int i = 0; i < (1e5 + 1); ++i) ans += a_count[i] * i;
  return ans;
}
int main() {
  int N, Q;
  vector<int> A, B, C;
  cin >> N;
  A = vector<int>(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  cin >> Q;
  B = vector<int>(Q);
  C = vector<int>(Q);
  for (int i = 0; i < (Q); ++i) cin >> B[i] >> C[i];
  vector<ll> S(Q);
  vector<int> a_count(1e5 + 1);
  for (int i = 0; i < (N); ++i) a_count[A[i]]++;
  for (int i = 0; i < (Q); ++i) {
    int b = a_count[B[i]];
    a_count[B[i]] = 0;
    a_count[C[i]] += b;
    S[i] = sum_by_a_count(a_count);
  }
  for (int i = 0; i < (Q); ++i) cout << S[i] << endl;
  return 0;
}
