#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 100100100;
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  for (int i = 0, i_len = (N); i < i_len; ++i) cin >> A[i];
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0, i_len = (Q); i < i_len; ++i) {
    cin >> B[i];
    cin >> C[i];
  }
  int sum = 0;
  vector<int> cntA(10000000, 0);
  for (auto a : A) {
    sum += a;
    cntA[a]++;
  }
  for (int i = 0, i_len = (Q); i < i_len; ++i) {
    int inc = (C[i] - B[i]) * cntA[B[i]];
    cntA[C[i]] += cntA[B[i]];
    sum += inc;
    cout << sum << endl;
  }
  return 0;
}
