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