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