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