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