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