#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
const ll INF_ll = 1e17;
const int INF = 1e8;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> X(1e5 + 1, 0);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    X[A[i]]++;
    sum += A[i];
  }
  int Q;
  cin >> Q;
  vector<ll> ans_v;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    int n_B = X[B];
    X[C] += n_B;
    X[B] = 0;
    sum = sum - B * n_B + C * n_B;
    ans_v.push_back(sum);
  }
  for (int i = 0; i < Q; i++) {
    cout << ans_v[i] << endl;
  }
  return 0;
}
