#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using vec_i = std::vector<int>;
using vec_ll = std::vector<ll>;
using vec_ld = std::vector<ld>;
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  map<int, int> A;
  int sum = 0;
  for (auto i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A[a]++;
    sum += a;
  }
  int Q;
  cin >> Q;
  vec_i B(Q);
  vec_i C(Q);
  for (auto i = 0; i < Q; ++i) {
    int b;
    cin >> b;
    int c;
    cin >> c;
    int nb = A[b];
    sum += nb * c - nb * b;
    A[c] += A[b];
    A[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}
