#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long int N, Q;
  int *A;
  int A_count[100000] = {0};
  int B, C, s = 0;
  int diff;
  int j;
  cin >> N;
  A = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    s += A[i];
  }
  sort(A, A + N);
  for (int i = 0; i < N; i++) A_count[A[i]] += 1;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    diff = C - B;
    s += diff * A_count[B];
    A_count[C] += A_count[B];
    A_count[B] = 0;
    cout << s << '\n';
  }
  delete[] A;
}
