#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
int main() {
  int N, Q;
  int A[MAX], B[MAX], C[MAX];
  long long table[MAX + 1] = {0};
  long long sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < N; i++) {
    table[A[i]]++;
  }
  for (int i = 1; i <= MAX; i++) {
    sum += table[i] * i;
  }
  for (int i = 0; i < Q; i++) {
    sum -= table[B[i]] * B[i];
    sum -= table[C[i]] * C[i];
    table[C[i]] += table[B[i]];
    sum += table[C[i]] * C[i];
    cout << sum << endl;
  }
  return 0;
}
