#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N;
  long long int maxim = 0;
  cin >> N;
  vector<long long int> A(N);
  for (long long int i = 0; i < N; i++) {
    cin >> A[i];
    if (maxim < A[i]) {
      maxim = A[i];
    } else {
    }
  }
  long long int Q;
  cin >> Q;
  vector<long long int> B(Q);
  vector<long long int> C(Q);
  for (long long int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    if (maxim < C[i]) {
      maxim = C[i];
    } else {
    }
  }
  map<long long int, long long int> counter;
  for (long long int i = 0; i < N; i++) {
    counter[A[i]] += 1;
  }
  for (long long int j = 1; j <= maxim; j++) {
    if (counter[j] < 1) {
      counter[j] = 0;
    } else {
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < Q; i++) {
    counter[C[i]] += counter[B[i]];
    counter[B[i]] = 0;
    for (long long int j = 1; j <= maxim; j++) {
      ans += counter[j] * j;
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}
