#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int main(void) {
  map<int, int> m;
  int N, Q;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    m[A[i]]++;
  }
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i];
    cin >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    int temp = m[B[i]];
    m[C[i]] += temp;
    m[B[i]] = 0;
    int sum = 0;
    for (auto x : m) sum += x.first * x.second;
    cout << sum << endl;
  }
  return 0;
}
