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