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