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