#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;
int main() {
  ll N, Q, sum = 0;
  cin >> N;
  vel A(2 * N), count(2 * N);
  for (ll i = 0; i < (ll)(2 * N); i++) count[i] = 0;
  for (ll i = 0; i < (ll)(N); i++) {
    cin >> A[i];
    count[A[i] - 1] = count[A[i] - 1] + 1;
  }
  cin >> Q;
  vel B(2 * Q), C(2 * Q);
  for (ll i = 0; i < (ll)(Q); i++) {
    cin >> B[i] >> C[i];
  }
  for (ll i = 0; i < (ll)(N); i++) sum = sum + A[i];
  for (ll i = 0; i < (ll)(Q); i++) {
    sum = sum + count[B[i] - 1] * (C[i] - B[i]);
    count[C[i] - 1] = count[C[i] - 1] + count[B[i] - 1];
    count[B[i] - 1] = 0;
    cout << sum << endl;
  }
}
