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