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