#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;
int kaz[100005];
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    kaz[A[i]]++;
    sum += A[i];
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    sum -= kaz[B[i]] * B[i];
    sum += kaz[B[i]] * C[i];
    kaz[C[i]] += kaz[B[i]];
    kaz[B[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
